The Archives


I’m Attending


Tag Archives: testing

Technical Debt Presentation

Posted in: Programming by Steve on October 22, 2010

Codemash 2011 registration opens today, so to celebrate, here is a video and presentation deck from Gary Short’s talk on Technical Debt.  It was one of my favorites.

Legacy Code Under Test Revisited and Working

Posted in: Programming by Steve on September 18, 2010

So after writing my last post, I was trying to look at it from a high level again.  The condition I was trying to determine was only if a single value on a parameter was set to a particular value.  In this case, my test was:

public void user_added_to_position_sets_default_of_IsAssigned_equals_true_value()
  // test goes here

In essence, I want to verify that IsAssigned = true when it’s being saved for the first time.  In my last blog post, I was making sure that the entire entity matched instead of just this single value.  This devalued the test and didn’t test for the condition I was expecting. 

So I rewrote the assertion to look like this:

Isolate.Verify.WasCalledWithArguments(() => posUserRepo.Save(null, ref tran))
   .Matching(args => (((PositionUsersEntity) args[0]).IsAssigned));

Trying to make the test more simple ended up fixing my problem. 

Wrangling your Legacy Code

Posted in: Programming by Steve on September 17, 2010

I was working on getting a piece of legacy code under test.  I had all the pieces in place, refactored and set to go.  I tried to run a failing test and BOOM: the unexpected. 

The test failed, but for a reason that I can’t explain.  The entity that I was trying to verify was calling the database, even though I was not explicitly calling the database.  I actually had the whole transaction mocked.  However, when Typemock was trying to verify that something was called with an exact argument:

Isolate.Verify.WasCalledWithExactArguments(() => _posRepo.Save(pos, ref tran));

The “pos” entity was calling code that I didn’t want it to.  I went to debug the test to make sure I wasn’t crazy, and sure enough: this line of code was the culprit.  It didn’t have anything to do with the method I was testing, but one of the properties in the “pos” entity was calling the database.

My next course of action is to change the “pos” entity to a mocked entity to see if that will “fix the glitch” but I was rather upset that I was fighting the tooling instead of fixing the problem.  The code works, just not under test.