3. Unit Testing with JUnit
JUnit 4.x is a test framework which uses
annotations to identify methods that are test
methods. JUnit assumes that all test methods can
be executed in an arbitrary order. Therefore tests
should not depend on other tests.
http://en.wikipedia.org/wiki/JUnit
8. Annotations
Annotation Description
@Test Test method
@Before Execute before each test
@After Execute after each test
@BeforeClass Execute once before all
tests
@AfterClass Execute once after all tests
@Ignore Ignore test
@Test (expected = Fails if not exception
Exception.class)
@Test(timeout=100) Fails if timeout
9. Assertions
Assertion Description
fail(string) Fails with message
assertTrue([message], Asserts if true
boolean condition)
assertsEquals([String Asserts if equal
message], expected,
actual)
assertNull([message], Asserts if object is null
object)
assertNotNull([message], Asserts if object is not null
object)