In TestNG you don’t need to extend any special class or use any naming convention for test methods(You may remember the test case names need to start with test in Junit 3), Now we just use the annotation @Test to signal to the framework the methods of the class that are tests. There have two test methods in following illustrates. Note that the assert Java instruction is used to check error conditions.
//TestNGSimpleTest .java
//TestNGSimpleTest .java
- package example.test;
- import org.testng.annotations.*;
- public class TestNGSimpleTest {
- int testInt;
- @BeforeMethod
- public void setUp() {
- testInt = 0;
- }
- @Test
- public void addTest() {
- testInt++;
- assert (testInt == 1);
- }
- @Test
- public void subtractTest() {
- testInt--;
- assert (testInt == -1);
- }
- }
No comments:
Post a Comment