有人可以解释我什么时候@AfterMethod(alwaysRun = true)应该执行。它会在什么时候执行@test方法被跳过。在文档中是这样写的,但我观察到了不同的行为。
示例: 代码:
public class testing{
@Test
public void testCase2(){
System.out.println("in test case 2");
Assert.assertEquals(1,2);
}
@Test(dependsOnMethods = { "testCase2" })
public void testcase3(){
System.out.println("OK");
}
@AfterMethod(alwaysRun = true)
public void afterMethod2() {
System.out.println("in afterMethod");
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
in test case 2
in afterMethod
FAILED: testCase2
java.lang.AssertionError: expected [2] but found [1]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:494)
at org.testng.Assert.assertEquals(Assert.java:123)
at org.testng.Assert.assertEquals(Assert.java:370)
at org.testng.Assert.assertEquals(Assert.java:380)
at app.testing.testCase2(testing.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at …Run Code Online (Sandbox Code Playgroud)