Note that there are some explanatory texts on larger screens.

plurals
  1. POAre there any conventions of extending JUnit4 test classes?
    text
    copied!<p>I have a lot of common logic for my test, so I decide to share it by extending. I've wrote two classes: <code>TestNumberOne</code> which extends <code>TestBase</code>.</p> <p><em>TestBase.java</em></p> <pre><code>import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; /** * @author Pavel * @since 2013-03-03 */ public class TestBase { @BeforeClass public static void beforeClass() { System.out.println("beforeClass() in TestBase"); System.out.flush(); } @AfterClass public static void afterClass() { System.out.println("afterClass() in TestBase"); System.out.flush(); } @Before public void before() { System.out.println("before() in TestBase"); System.out.flush(); } @After public void after() { System.out.println("after() in TestBase"); System.out.flush(); } } </code></pre> <p><em>TestNumberOne.java</em></p> <pre><code>import org.junit.*; /** * @author Pavel * @since 2013-03-03 */ public class TestNumberOne extends TestBase { @Test public void anyTest() { System.out.println("anyTest() in TestNumberOne"); System.out.flush(); } } </code></pre> <p>I've got such a strange output when I execute my tests:</p> <pre><code>before() in TestBase anyTest() in TestNumberOne after() in TestBase beforeClass() in TestBase afterClass() in TestBase </code></pre> <p>Why does it has so strange order? And are there any conventions of extending JUnit test classes?</p> <p>UPDATE:</p> <ol> <li>Tests are run in IDEA </li> <li>To get such a strange results I've run them several times (other results was as expected)</li> </ol>
 

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