1

When I run the my unit tests, they immediatly are being terminated. However no logging is presented. (only 'Failed to start' and 'Process finished with exit code 255').

Tests worked before... JUnit 4 does not give me this problem. Test do run succesfully in Maven.

I use JUnit5 Jupiter and IntelliJ IDEA 2020.1 (Ultimate Edition).

Anyone any thoughts?

Flo
  • 11
  • 1
  • 2

5 Answers5

2

I was experiencing the same behaviour as described in this question. What fixed the problem for me was removing conflicting dependencies:

    Remove similar entries ->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.2.0</version>
    </dependency>

as it is already included by spring-boot-starter-test. Removing the explicit dependency will enable SpringBoot to handle incompatible version issues between dependencies for you.

Konstantin Grigorov
  • 1,356
  • 12
  • 20
1

@Before and @After no longer exist; use @BeforeEach and @AfterEach instead.

@BeforeClass and @AfterClass no longer exist; use @BeforeAll and @AfterAll instead.

https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4-tips

m4n0
  • 29,823
  • 27
  • 76
  • 89
0

I just had the same issue.

The single thing that fixed this - and which I could reproduce - is this: don't .close() System.out (or System.err).

@Test
void failure()
    {
    System.out.close();
    }

makes happen what you describe.

Wherever I passed System.out to functions that would .close() their OutputStream later, I replaced them with a new ByteArrayOutputStream() instead.

foo
  • 1,968
  • 1
  • 23
  • 35
0

After experiencing the same, I've debugged only to find that tests are completely executing and all assertions pass.

I've managed to narrow the issue down to System.out.println call whose output is somehow being held until all the tests are complete before, and eventually flushed, before IDEA gets to claim that test was interrupted.

Removing a reference to System.out from test code makes the tests go green in IDEA again.

tishma
  • 1,855
  • 1
  • 21
  • 43
0

For me using @BeforeEach and @AfterEach worked instead of @BeforeAll and @AfterAll

Ishwor Upreti
  • 27
  • 1
  • 8