Note that there are some explanatory texts on larger screens.

plurals
  1. POApply '@Rule' after each '@Test' and before each '@After' in JUnit
    primarykey
    data
    text
    <p>I have a test suite where I am logging out of the system in <code>@After</code> and closing the browser in <code>@AfterClass</code>. I am trying to use <code>@Rule</code> to take failed test screenshot using Selenium for every test method. I checked manually that <code>@Rule</code> only runs before every <code>@Before</code> but I want to set it up after <code>@Test</code> and before <code>@After</code>. I couldn't find out simple solution. Any help will be appreciated. </p> <pre><code>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; } } </code></pre> <p>The output I am getting is </p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload