Annotations

48 views
Skip to first unread message

====

unread,
Apr 20, 2017, 2:09:39 PM4/20/17
to testng-users
I have problem understanding what is the difference between @Before/After Test and @Before/After Method annotations. Please help.

SUBRAMANYESWARA RAO BHAVIRISETTY

unread,
Apr 21, 2017, 11:07:17 PM4/21/17
to testng-users
Explanation in one of the previous emails  of the group.

@BeforeMethod is invoked before each method with a @Test annotation.

@BeforeTest is invoked before a <test> tag.

<test>
  <classes>
    <class name="A" />  <-- contains tests a1() and a2()
    <class name="B" />   <-- contains tests b1() and b2()
  </classes>
</test>

In this case, you will see:

@BeforeTest
  @BeforeMethod
    a1()
  @AfterMethod
  @BeforeMethod
    a2()
  @AfterMethod
  @BeforeMethod
    b1()
  @AfterMethod
  @BeforeMethod
    b22()
  @AfterMethod
@AfterTest

Hope this clears things up.


On Thu, Apr 20, 2017 at 11:09 AM, ==== <abr...@gmail.com> wrote:
I have problem understanding what is the difference between @Before/After Test and @Before/After Method annotations. Please help.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
Subramanyam

Hoang Nguyen

unread,
May 17, 2017, 11:21:12 PM5/17/17
to testng-users
the different is affect scope:

@Before/After Test are affected to tag <test> in xml suite
@Before/After Method are affected to annotation @Test in your class file



Vào 01:09:39 UTC+7 Thứ Sáu, ngày 21 tháng 4 năm 2017, ==== đã viết:
Reply all
Reply to author
Forward
0 new messages