
Annotations have made some of the programming stuffs easier because they do a lot of things in the background, which any programmer would otherwise needed to have coded by themselves. JUnit uses a bunch of annotations and represents various separate tasks they do behind the scene. Here are some of the most widely used annotations from Java based Unit Testing Framework – The JUnit. If you would like to see a comprehensive example of JUnit with all these annotations in action, see my previous article on JUnit Test Case
- @Test
- Denotes a test method. Can be used with expected to assert expected results on the object under test.
- @Before
- Run before each test method is run i.e. do a setup
- @After
- Run after each test method is run i.e. do a teardown
- @BeforeClass
- Run before all the tests in a class (Runs once for all of the tests)
- @AfterClass
- Run after all the tests in a class (Runs once for all of the tests)
- @Parameters
- Allows you to run the same test with different data by defining the data parameters. @Parameters have to return List[], and the parameter will pass into class constructor as argument.
- @RunWith
- Exclusively tells the class that the Junit Test Case uses Parameterized runner
Originally posted 2012-02-06 19:21:52.