-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Milestone
Description
Sample code:
public class BeforeAfterMethodTest {
@Test
public void testWithoutBeforAndAfter() {
System.out.println("testWithoutBeforAndAfter");
}
@Test
public void test() {
System.out.println("test");
}
@BeforeMethod(dependsOnMethods = "test")
public void beforeMethod() {
System.out.println("before");
}
@AfterMethod(dependsOnMethods = "test")
public void afterMethod() {
System.out.println("after");
}
}
Result:
org.testng.TestNGException:
test.BeforeAfterMethodTest.beforeMethod() is depending on method public void test.BeforeAfterMethodTest.test(), which is not annotated with @Test or not included.
at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:111)
at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:240)
at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:317)
at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:59)
at org.testng.internal.TestNGMethodFinder.findConfiguration(TestNGMethodFinder.java:191)
at org.testng.internal.TestNGMethodFinder.getBeforeTestMethods(TestNGMethodFinder.java:64)
at org.testng.TestClass.initMethods(TestClass.java:167)
at org.testng.TestClass.init(TestClass.java:86)
Regarding documentation:
http://testng.org/javadoc/org/testng/annotations/BeforeMethod.html#dependsOnMethods()
The list of methods this method depends on. There is no guarantee on the order on which the methods depended upon will be run, but you are guaranteed that all these methods will be run before the test method that contains this annotation is run. Furthermore, if any of these methods was not a SUCCESS, this test method will not be run and will be flagged as a SKIP. If some of these methods have been overloaded, all the overloaded versions will be run.
My expectation was that the before and after method will be run only before and after test() method.
Please can you provide some fix or explanation.
Thank you.