There are two mainly annotations in TestNG:
@Configuration
and @Test
.
This annotation is used to make any method a setup or a teardown method. In addition, the @Configuration makes unnecessary to follow any naming convention in method names. The mainly properties that could be used are:
afterTest
- if true, the method will be run after
each test.
afterTestClass
- if true, the method will be run
after all the tests in the test class.
beforeTestClass
- if true, the method will be run
after the test class instantiation and before tests methods.
beforeTestMethod
- if true, the method will be run
before any test method.
In the example, the method setup()
will request a new
bean instance before any test method.
/** * Gets a new bean instance used during the tests. * @throws Exception if an error occurs during the setup. */ @Configuration(beforeTestMethod = true) public void setup() throws Exception { // Gets a bean instance. bean = getBeanRemoteInstance(SLSBExample.class, ItfExample.class); }
This annotation is used to define a method that will be run as a
test and it is not necessary follow any naming convention. In the
example, the method test00()
has the annotation and it will
be a test case:
@Test public void test00() throws Exception { ... }
If it is necessary to disable this test, the enabled
property could be used:
@Test(enabled = false) public void test00() throws Exception { ... }