JUnit is one of the most used Unit Testing Frameworks for java.
Beginning from the version 4, it provides some very intuitive annotations to write your test:
@BeforeClass
Methods are executed once before the first of the series of tests. External resources that are used by all tests should be initialised here (i.e.: a database connection).
@AfterClass
Methods are executed once after the last test has been run.Resources used by the tests that need to be released such as streams etc. should be set free here.
@Before
Methods are executed before every single test. For example can you init your test data.
@After
Methods are executed after every single test. For example can you delete the output of your test.
@Test
Methods are the actual test methods. Here can you use the Assertion.
@Test (expected = ArrayIndexOutOfBoundsException.class)
The Test Annotation can be extended by stating what exception should be thrown when the test is executed, the test fails if no exception or if the wrong exception is thrown.
@Ignore
Don't run tests, that are not yet implemented.
Saturday, February 16, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment