Written by Erich Gamma (of Design Patterns fame) and Kent Beck (creator of XP methodology)
A simple framework to write and run repeatable tests
JUnit features include:
The @Test annotation identifies a method as a test method.
It was setUp and tearDown ?
Run once for each test method in fresh instance of the test classes such as if one test modifies a class field, the second will not be affected. The tests run completely independently.
You only need to implement an after method if the before method has allocated external ressources. If the before method has allocated plain java object you can ignore after. Hoewer if you allocate many megabyte of objects you might want to clear the variables pointing to these objects so they can be garbage-collected.
This method are executed once, before and after the start of all tests.
@BeforeClass
public static void method()
@Ignore
return;
assumeNotNull()
assumeNoException()
assumeTrue()
// AssumThat
// is = equal
assumeThat(targetDatabase.getDatabaseProductName(), is(Database.DB_SQLITE));
// not Null
assumeThat(Database.connect(), is(notNull()));
Test suite is a composite of test. It can then contains test suite and test.
The test will fails if the method takes longer than 1000 milliseconds.
@Test(timeout=1000)
The test will succeed if the method throw the named exception.
@Test (expected = Exception.class)
Assert is a collection of static method for checking actual values against expected ones.
Make sure that the junit.jar file is on classpath