CI and Unit Testing Processes

Working with unit tests and CI in a team environment poses some interesting process challenges. It's good to enforce the stigma of the Broken Build, but process should help prevent that scenario from ever occurring in the first place (disclaimer: I've been party to responsibility for broken builds twice in two days, ashamedly).

I'm thinking the following process should be enforced:

  1. Write Tests (TDD & all)
  2. Write Code to pass Tests
  3. Refactor
  4. Make sure Code passes Tests
  5. [placeholder -- ready for checkin] Prepare for checkin by:
  6. Update code (get latest)
  7. Build
  8. Run All Tests
  9. Refactor as needed
  10. Checkin Code

If this process is not used, there's a more serious concern of regression tests only getting caught at the automated CI build, rather than through the everyday making sure that tests are going to pass proactively prior to actually submitting code to the source engine.

Posted on 10/28/2008 5:31:00 PM by Jason Nadal

Permalink | Comments |

Categories: development | tdd

Tags: , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Unit test and mocking resources

In order to make writing unit tests easier, Ayende Rahien has come up with a mocking framework for hte .NET framework. These mock objects "pretend" to implement interfaces, and display expected behavior for tests.

Some resources available for learning the basics are:

Posted on 10/12/2008 6:31:00 PM by Jason Nadal

Permalink | Comments |

Categories: development | tdd | unitTesting

Tags: , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Retrofitting Unit Tests -- NCover to the rescue

Writing unit tests is the right thing to do to provide regression testing and just provide some proof that things work how they should. They are the safety net that make sure that when you change the facing on the capstone that the rest of the arch won't collapse.

That being said, one does not always get the opportunity to invest the time it takes to get past that big learning curve to make it part of the daily toolbelt. But knowing unit testing will help in the long term, you get the itch to add them after the fact.

The problem is that they're much harder to just tack on as methods aren't guaranteed to be truly granular in their purpose. Methods and classes tend to be responsible for too much. So how can you write tests to cover all of the responsibilities?

The simplest answer is to write to what you know. I know that Method FastCash() logs into my bank account and withdraws $60. So I write a unit test to check a good login, bad login, pad pin number, scenario where I have $60 to withdraw, and a scenario where I'd be overdrawn. Seems like a decent bunch of simple tests for the FastCash() method, right?

Well, by using NCover, you can run coverage reports on your unit tests. When I do this, I discover i'm only hitting 67% of the logic of the FastCash method. As it turns out, there's a third bit of functionality in there -- automatically, it assumes you choose the Checking account. NCover shows you the lines that are not getting hit by your unit tests, and allows you to specifically target those additional scenarios you weren't truly testing.

I was able to put this into good use today while finding some pure business logic classes. That makes it much more simple to write unit tests for as there are minimal dependancies and coupling occasional, and a great opportunity for well defined acceptance criteria. Both make it that area of code a natural fit for unit testing.

Posted on 10/10/2008 6:21:00 PM by Jason Nadal

Permalink | Comments |

Categories: development | software | troubleshooting | tdd

Tags: , , ,

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5