javarosa
javarosa copied to clipboard
Migrate tests to jUnit4
We currently have 22 test classes that use the old TestCase
jUnit API.
Modern tools and IDEs support jUnit4's @Test
annotations that let us have more useful interactions with the test code base:
- Improved test result reports, by separating each test's results.
- Run only one test suite/class/method or a set of them
I'm proposing we migrate the 22 test classes to jUnit4's modern API. To do so, one would have to go through them and follow this rough list of steps:
- Remove the extension on
TestCase
- Add a
@Before
annotation onsetUp
and remove the call onsuper.setUp()
- Add a
@Test
annotation on all methods listed ontestMaster()
. - Remove
testMaster()
andsuite()
- Remove the class constructor
Also, we should be on the look out for these other scenarios to migrate them as well:
- Any try-catch blocks with a
fail()
on the catch should be removed and let the method throw. Junit will capture the exception and fail the test with a proper error message. - Setup and teardown code must be extracted to methods with
@Before
,@BeforeClass
,@After
, and@AfterClass
annotations. Otherwise, when an assertion fails, the teardown is not executed, possibly affecting to other tests on the suite if the setup method has collateral effects on the filesystem,Calendar
,Locale
, etc.
Some specific tests like XPathEvalTest
would benefit from a deeper migration by using @Parameterized
test execution (example here: https://github.com/opendatakit/javarosa/pull/272/commits/836243c121e2744415f079d3f3a61536eb1b259f )