Out Of The PARC
Tuesday, June 10, 2003

 
Would you like one test method or two?

A couple of us have been musing recently about the preferences to combine multiple tests into one test method, or split them into two. One member of our group had been combining 5-15 tests into a single test method. Each distinct test was fairly simple -- one line of code. All independent, so they could have been each in their own JUnit test method, or all together. Let's ignore the temptation to boost the total number of tests for the purpose of bragging rights -- "we have over 700 tests in our suite".

My thoughts are to put the tests together when:
(a) the set-up to perform one of the tests passes through the set-up for another test, or
(b) within the context of a TestCase, two simple tests are closely related to each other more than they are to other tests in the same TestCase.

Other than that, I prefer the tests to be in separate test methods. This way, when I break something, the presence or absence of multiple failures (which won't happen when several tests are linearized in a single test method) can help me triangulate on where th error actually is.

Powered by Blogger