J. B. Rainsberger wrote:
> Kent Beck wrote:
>> Apparently I haven't stated this strong enough in the past. You should
>> assume that each test method will be run with a fresh test method in JUnit.
>> This has been part of the architecture from the beginning and I don't see
>> any reason to change it. The principle behind this choice is that tests
>> should be order-independent. Running with separate instances supports
> That's fine. As I think about it, there's still another reason not to
> initialize objects in the constructor: test instance creation happens
> well before the test runs, so if too much initialization happens in the
> constructor, one might run out of memory before running any tests.
Just to further clarify, this is JUnit 3 behavior. In JUnit 4.1, test
instance creation happens right before test execution, so this
particular reason to favor setUp is no longer the case. As Kent has
noticed, this is not yet an API guarantee for 4.x, however.
Share and enjoy,