Archive for November, 2009

Mock Data Testing with Spring and HSQLDB part 1

Tuesday, November 24th, 2009

I wanted to share some interesting things that myself and my colleague Emil “Bud” Lefkof have done recently in the realm of Mock Testing using Spring and HSQLDB.

I expect this to be the first of threetwo posts on this topic. First I’ll explain the problem that this approach solves. In the second post I’ll explain the approach. In the last post I’ll discuss some additional concerns such as having to deal with Stored Procedures.

For an explanation of Mock Object Testing see Wikipedia who actually does a nice job of explaining what it is all about.

The reason that Mock Testing is important is that Unit tests should be repeatable and automated. Developers should be able to check out code and unit tests from a source control system and be able to run a script or command that builds and tests. Unit tests shouldn’t need to rely on databases, or other external dependencies. Plus the state of a database can become unknown. When doing test driven development you need to be able to run a test over and over again. You can’t worry about the data already being in the database.

I was first introduced to the concept of Mock Testing by my old friend and colleague Howard Spector during my time at FirstUSA/Bank One Card Services.  It was my first experience with Test Driven Development.  Back in those days we had our own Data Services Framework.  This was a framework that provided an interface that was an abstraction over Relational Database.

Because this framework was an interface we could use test implementations that would return mock data objects.  However it always felt clumsy.  Creating the test data was a manual time consuming task.  There were 2 ways to create the Mock Data objects. 

The first way is to hand code a factory that would set the values of the properties of data objects.

public List getDataPojos(String arg){
  List returnList = new LinkedList();

  DataPojo dataPojo1 = new DataPojo();
  dataPojo1.setString1("String 11");
  dataPojo1.setString2("String 12");
  returnList.add(dataPojo1);

  DataPojo dataPojo2 = new DataPojo();
  dataPojo2.setString1("String 21");
  dataPojo2.setString2("String 22");
  returnList.add(dataPojo2);

  return returnList;
}

Another option that has a little bit more flexibility is to parse a properties file or XML file.

With either approach there needs to be some sort of translation from the source to the Mock Data object that is essentially throw away code. This will cause the developer to spend more time writing code to create Mock Data objects than writing the actual tests or even the actual code.

In my next post I’ll detail how we can solve the issue of spending too much time creating Mock Data objects.

When do you leave a job?

Tuesday, November 24th, 2009

Long gone are the days that you work your entire career with one employer.  Long gone are the days that you would even spend more than a decade with the same employer.  I was told in college that as you are starting out in your career you should move around on average every 18 months.  This was especially true during the tech bomb of the late 90′s.  For a while I did that.  By the time I was 6 years out of College, I was on my 4th company.

Has that changed at all?  Right now we here in the United States are facing unemployment like we have not seen since the great depression.  I feel lucky that I currently have skills that are in demand.  A lot of people I know are not that lucky.  But I wonder for even the software developers out there has this economy made you think twice about pursuing new opportunities.

I had a hard time making this decision about a year ago.  The market had already started it’s down turn.  I wasn’t getting assignments that were a fit for my skills and location.  I spent a great deal of time in 2008 sitting on the bench.  Granted I got paid.  But I was a draw on the company’s bottom line.  For me there was nothing worse than having to report to the office every day (even if it was an abbreviated day.) and not have work that someone counted on me producing.  I was given some bench assignments.  But there was little collaboration.  I’m one to thrive on the back and forth of the work day.

I loved my time with that old consulting company.  I had great friends there.  I had gone through some tough times while I was there in my personal life.  They were always great to me.  I felt like I was well respected.  But it was time to leave.  I have yet to regret a decision I have made in my career.  I don’t regret leaving.  Although I would not be opposed to working with them again in the future.

So what are the types of things that you look for when you decide to move on?

  • Better Pay
  • More exciting work
  • Change in management
  • Change in direction of your company
  • More responsibility
  • Less responsibility
  • Work environment

For me it was “More exciting work” and “different work environment.”

Right now I am working as a Contractor.  I see myself having to make these decisions a lot more in the future.  I also see these decisions being made for me as well.  My original contract was set to expire at the end of the year.  I’ve since been extended until April 30th.  I am grateful that I will have a contract through the lean months of November, December, January and start of February.