在 JUnit 中,在每个“@Test”之后和每个“@After”之前应用“@Rule”
2022-09-02 12:32:25
我有一个测试套件,我正在注销系统并在.我正在尝试使用硒为每个测试方法使用失败的测试屏幕截图。我手动检查了仅在每个之前运行,但我想在之后和之前设置它。我找不到简单的解决方案。任何帮助将不胜感激。@After
@AfterClass
@Rule
@Rule
@Before
@Test
@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