Freitag, 3. Juni 2011

Pitfalls of migrating JUnit 3 test cases to JUnit 4

How to migrate JUnit 3 test cases to JUnit 4 is explained in Get Acquainted with the New Advanced Features of JUnit 4, e.g.
But after I migrated my tests as described, some of my tests didn't work, anymore. Tests extending  a common abstract base class that provided common setup and teardown logic:

abstract class AbstractTestCase extends TestCase {

   protected AbstractTestCase() {
   }

   @Before
   protected void setUp() throws Exception {
      // common setup logic
   }
}

Although I added the Before-Annotation to the setUp()-method, it didn't get called. So, I changed the visibility of the method to public. This didn't fix the problem, either. After some pondering and fruitless searches on the Web, I changed the visibility of AbstractTestCase from package-protected to public. Behold, it worked again.

Keine Kommentare:

Kommentar veröffentlichen