... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2006-08-14

JUnit 4.0 BeforeClass Annotation

The JUnit @BeforeClass annotation has different semantics than the BeforeClass property in TestNG.  JUnit's version is invoked before any instances of the test case class are instantiated and, thus, can only access static features of the class.

Another gotcha to watch out for is that JUnit does not invoke any of the @BeforeClass or @Before methods of the superclasses of the test class.

I note that the Eclipse wizard for creating JUnit test cases does not permit you to specify a superclass -- is this a hint that the practice is discouraged?  Delegation appears to be the alternative, along with the use of static fields (ugh -- global variables).

Blog Archive