Search This Blog

14 May 2010

Initializations during test cases

In any larger project a complex test suite should be built, a test suite that when run through should cover most of the code that handles buisness logic, aggregations and such. Presentations aren't always that important even if it is good to include those parts in the tests too,When the tests starts to increase they will take longer and longer to complete which will impact on the performance of the developers since these have to wait for tests to complete during verficiations of changes.

There are several methods for dealing with this one is the use of a common initializations class that setup the basic structure and adds basic data needed for the tests. The problem with this approach is that if you need to add some new data or change data in the setup you will have a huge impact on the tests and maybe changing a few that  should have given indications on a problem that has been introduced. Its often better to separate the tests and let each test setup the data required for just that test and clean up afterwards. If using a database the setup and teardown of the database could be a common setup that is run first in the testclass and teardown occured at the end after all tests. In such an instance you need a way to clean out the database without tearing it down compleatly.

Of course these are just my thoughts and there a several methods in dealing with this. One that we often use is the use of mocking of objects since you then don't need a real database just the apperance of one. from the systems point of view. This makes that test much much more efficient and faster but has the drawback that you aren't really testing the database which also needs to be done.

I any circumstance test ARE important and you should never feel that a test is useless and remove them if you aren't compleatly and absolutly sure since there is often a very good reason for that the test was created in the first place.

Happy testing!

No comments:

Post a Comment