Re: [junit] setUp versus constructors
- J. B. Rainsberger wrote:
> Kent Beck wrote:Just to further clarify, this is JUnit 3 behavior. In JUnit 4.1, test
>> 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.
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,
- David Saff wrote:
> In JUnit 4.1, test instance creation happens right before testIn JUnit 4.2, it will be a guarantee that the provided test runners will
> execution[...]. As Kent has noticed, this is not yet an API guarantee
> for 4.x, however.
create test instances right before test execution and release them right
after. You can cheat and depend on this behavior in 4.1 starting now,
if you wish.