为什么TestNG的执行@AfterMethod为@Test如果我的第一个测试通过?
例如,如果我的第一个测试失败的testoutput是:
1 test passed, 1 test failed.(3599,0 s)
TestSuite FAILED
run FAILED: check5=3 Expected: <3> got: <5>
run passed (1.0s)
但是,如果我只是切换的测试用例的顺序,因此先会过去,我得到这样的:
3 test passed, 2 test failed.(2867,0 s)
TestSuite FAILED
run passed (1.0s)
run FAILED: check5=3 Expected: <3> got: <5>
AfterMethod FAILED (4,0 s) // <--- wtf, this is not an @Test
AfterTest passed (5,0 s)
AfterSuite passed (15,0 s)
怎么了? 我testngsuite.xml:
<suite name="TestSuite_03">
<test name="TestCase_17">
<groups>
<run><include name="functest"/></run>
</groups>
<classes>
<class name="TestStep_003" desc="will pass" />
<class name="TestStep_012" desc="will fail" />
</classes> ...
我使用Maven,通过NetBeans的TestNG的和Java
我的结构:
public abstract class TestCommon
{
@BeforeSuite(groups={"functest"})
public void BeforeSuite()
{
// clean report folder
}
@BeforeTest(groups={"functest"})
public void BeforeTest()
{
// start selenium browser
}
@AfterMethod(groups={"functest"}) // this is not a @test, still gets shown as failed
public void AfterMethod()
{
// check for failure and capture screenshot
}
@AfterTest(groups={"functest})
public void AfterTest()
{
// close browser
}
}
public class TestStep_003 extends TestCommon
{
@Test(groups = {"functest"})
public void run()
{
assertThat(5, Matchers.equalTo(5)); // will pass
}
}
public class TestStep_012 extends TestCommon
{
@Test(groups = {"functest"})
public void run()
{
assertThat(5, Matchers.equalTo(3)); // will fail
}
}
Annother问题是,testoutput不是为了,时间戳不是旧的 - >更新,也有旧之间新的:这就是我的输出如何看起来像:
1327840359762: TestStep_012.AfterMethod // this is not the oldest timestamp!
1327840359763: TestStep_003.run
1327840359765: TestStep_003.AfterMethod
1327840357189: TestStep_012.BeforeSuite
1327840357192: TestStep_012.BeforeTest
1327840359758: TestStep_012.run
1327840359762: TestStep_012.AfterMethod
1327840359763: TestStep_003.run
1327840359765: TestStep_003.AfterMethod
此外,只有2种方法TestStep_003.run和和TestStep_012.run,和它仍然显示AfterMethod 4倍