Showing posts with label unit testing. Show all posts
Showing posts with label unit testing. Show all posts

Friday, March 21, 2008

The way I'm working lately

This is actually almost fun.

Figure out some functionality that needs to exist. Within a unit test, write the top-level code for it regardless of whether the supporting methods exist or not.

List people = populationDao.getPeople();

...even if I haven't written populationDao.getPeople() yet.

Eclipse will complain that I have written references to methods that don't exist. Hit control-1 and choose the answer that is "create method 'getPeople' in interface 'populationDao'." Then, of course, PopulationDaoImpl will have errors, because I have a method in populationDao that I haven't implemented. Open up PopulationDaoImpl, control-1, 'add unimplemented methods,' and write the implementation for getPeople().

This way I know that getPeople() has at least some test coverage right from the start.

Wednesday, February 20, 2008

Today I Am A Real Boy

Today a client coworker gave me some Java code of his to work on and finish up, because we're going to need it for forward development.

So I looked at what stuff could be refactored, wrote a couple of unit tests, refactored some bits out, ran the tests, and...

Well the code logged a few major exceptions and was unusable. But the test passed.

We were conversing about this code in general terms a few minutes later, and I pointed at the screen and hollered "I want that test to fail! Help me make it fail!"