Loading ...
Sorry, an error occurred while loading the content.

Re: [junit] setUp versus constructors

Expand Messages
  • David Saff
    ... 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
    Message 1 of 38 , Aug 1, 2006
    • 0 Attachment
      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
      >> independence.
      >>
      >
      > 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,

      David Saff
    • David Saff
      ... In JUnit 4.2, it will be a guarantee that the provided test runners will create test instances right before test execution and release them right after.
      Message 38 of 38 , Aug 3, 2006
      • 0 Attachment
        David Saff wrote:
        > In JUnit 4.1, test instance creation happens right before test
        > execution[...]. As Kent has noticed, this is not yet an API guarantee
        > for 4.x, however.

        In JUnit 4.2, it will be a guarantee that the provided test runners will
        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.

        David Saff
      Your message has been successfully submitted and would be delivered to recipients shortly.