KentBeck/junit — Issue #366: Support non-static inner classes
Author: nathanila
Created: 2011-12-02 17:46:56+00:00
State: open

Non-static inner classes are currently disallowed. This feature request is to allow for non-static inner classes. Only those classes that have @Test methods will be tested. The @Before method of the inner class is run after the @Before method of the outer class. The @After method of the inner class is run before the @After method of the outer class. Likewise, the same applies to @BeforeClass and @AfterClass.

When testing a class that implements an interface such as Map, it is very useful to write non-static inner classes which test the Sets and Collection which are implemented and returned by the class. For example, I could write a generic test class (MapTest) which enforces all of the specifications of the Map interface. Then, I can extend that test which tests specific features and specifications of the class which implements the Map interface. I could then write a generic test class (SetTest) which enforces all of the specifications of the Set interface. The MapTest class can then declare a non-static inner class which extends SetTest to test the methods of the Sets returned from keySet() and entrySet().