Re: [junit] Can I create a dynamic JUnit ? (in Cactus Framework)
- Cedric Beust wrote:
>> From: email@example.com [mailto:firstname.lastname@example.org] On Behalf OfDavid Saff
>> That's a little misleading and a little untrue. _If_ you run
>> JUnit on a class without a suite() method, or you have a
>> suite() method that calls TestSuite.addTestSuite(Class), then
>> _before any method is executed_, a fresh instance of the test
>> class is created for each test method in the class. However,
>> if you have a suite() method that calls
>> TestSuite.addTest(Test), which Donny did, then no such "automatic"
>> creation _should_ happen.
> Wow, you really had me there. I didn't believe it, so I tried it. And you
> are right.
> Now, what could possibly be the justification for this behavior?!?Cedric, I've been telling you this for a year or so... Tests get
instantiated at the start (one instance per test), they are run, and
then, depending on the runner, they are thrown away or reused. That's
why setUp and tearDown are important; they move expensive work to a
lifecycle around test execution.
The justification is for the tools. Look at the behaviour in IntelliJ
or Eclipse's test runners. You get a list of tests appearing, you can
see which one is being executed, you can tell which ones have failed,
and you can look at it afterwards to see why it failed. Yes, you can
do it in other ways (as you've done in TestNG), but that's why it was
done in JUnit 3. (4 also has this behaviour... the test
invoking-object is created at the start and held around).
You may want to re-read my JUnit Architecture Redux, Cedric...