我有一个测试套件,我在其中注销系统@After
并关闭浏览器@AfterClass
。我正在尝试@Rule
使用 Selenium 为每种测试方法拍摄失败的测试屏幕截图。我手动检查了@Rule
只在 every 之前运行,@Before
但我想在 after@Test
和 before 之前进行设置@After
。我找不到简单的解决方案。任何帮助将不胜感激。
public class MorgatgeCalculatorTest {
@Before
public void before(){
System.out.println("I am before");
}
@BeforeClass
public static void beforeclass(){
System.out.println("I am beforeclass");
}
@Test
public void test(){
System.out.println("I am Test");
}
@Test
public void test2(){
System.out.println("I am Test2");
}
@After
public void after(){
System.out.println("I am after");
}
@AfterClass
public static void afterclass(){
System.out.println("I am afterclass");
}
@Rule
ExpensiveExternalResource ExpensiveExternalResource = new ExpensiveExternalResource();
static class ExpensiveExternalResource implements MethodRule {
public ExpensiveExternalResource(){
System.out.println("I am rule");
}
@Override
public Statement apply(Statement arg0, FrameworkMethod arg1, Object arg2) {
// TODO Auto-generated method stub
return null;
}
}
我得到的输出是
I am beforeclass
I am rule
I am before
I am Test
I am after
I am rule
I am before
I am Test2
I am after
I am afterclass