4

We've been trying to figure out how to stop Greenmail so it doesn't occupy the 3025 port when a Junit test case fails.

When a unit test fails, Junit seems to bypass the @After annotation (correct if I'm wrong), and carries on with following tests. Unfortunately the other tests runs the @Before which starts a NEW greenmail server attempting to hook into port 3025, thus resulting in an ERROR in another test.

Ideally we want failure to be shown only on the ones which actually failed and not have 1 or 2 test cases fail the rest of the test suite due to Greenmail problems.

Any help?

Sample code


@Before
public void setup() {
    greenMail = new GreenMail(ServerSetupTest.SMTP);
    greenMail.start();
}

@After
public void tearDown() {
    greenMail.stop();
}

@Test
public void someFailTest() throws IOException{fail();};

@Test
public void someGoodTest(){assert(true);}; // greenmail busted so this also throws up
alwinc
  • 1,317
  • 3
  • 14
  • 21
  • Which junit and which GreenMail version do you use? When running with junit 4 and GreenMail 1.3.1b, I do see the Before/After annotated methods invoked for each test even if failing. – Marcel Oct 07 '14 at 07:46

0 Answers0