2

I'm using TestNG for some time now but still I don't know what's the intended purpose of those two (@Test and < test> in suite.xml)and what abstractions they are meant to express.

Also if anyone can share the difference in their behavior regarding other elements in TestNG. For example are @AfterTest @BeforeTest triggered by @Test or <test> and which one of @Test and < test> gets into the final execution report.

munch
  • 2,061
  • 2
  • 16
  • 23

2 Answers2

3

@Test denotes a test method. <test> is a how you group several classes together in your testng.xml.

Cedric Beust
  • 15,480
  • 2
  • 55
  • 55
  • is it possible to execute only classes under specific tag ?. Any idea for this issue ? https://stackoverflow.com/questions/47436748/how-to-run-a-single-classes-under-single-test-tag-in-testng-suite – Abdul Razak AK Nov 22 '17 at 15:05
3

Adding to Cedric's answer, on your second question

@AfterTest runs after in the xml

@AfterMethod runs after @Test in your java file.

eg.

public class TestCases{
@Test
public void test1()..
@Test
public void test2()..
}

public class MoreTestCases{
@Test
public void test1()..
@Test
public void test2()..
}

So you have 4 testcases annotated with @Test

Now, for in the xml is how you want to structure your running of tests

 <test>
   <classes>
    <class name = TestCases>
      <methods>
        <include name = test1/>
      </methods>
    </class>
   <class name = TestCases>
     <methods>
       <include name = test1/>
     </methods>
   </class>
  </classes>
</test>

So your now is run only test1 from both your classes.

The terminology is a bit confusing at the start...but I hope it helps clear things a bit.

niharika_neo
  • 8,441
  • 1
  • 19
  • 31
  • Thank you. I was expecting something like this kind of answer. Helped me understand better the idea and structuring. – munch Mar 06 '13 at 15:03