Maven error on spring boot (junit 5)

Is it possible to run spring boot tests with junit 5 using maven? I am using spring boot 2.0.0.M3, junit 5.0.0-M6, maven 3.5.0. Other junit5 tests (no spring context) work.

There is a simple controller:

@Controller
public class HomeController {
    @GetMapping("/")
    String home() {
        return "home";
    }
}

      

and the test:

@ExtendWith(SpringExtension.class)
@WebMvcTest(HomeController.class)
@Import(SecurityConfig.class)
class HomeControllerTest {

    @Autowired
    private MockMvc mvc;

    @Test
    void shouldReturnHomeTemplate() throws Exception {
        this.mvc.perform(get("/").accept(MediaType.TEXT_HTML))
            .andExpect(status().isOk())
            .andExpect(content().string(startsWith("<!DOCTYPE html>")));
    }
}

      

Everything works when I run it with intellij, but maven build fails:

[WARNING] Corrupted stdin stream in forked JVM 1. See dump file somePath / target / error-free-reports / 2017-07-28T13-50-15_071-jvmRun1.dumpstream

- debug flag shows:

java.lang.OutOfMemoryError: Java heap space

Inside 2017-07-28T13-50-15_071-jvmRun1.dumpstream

I can find ~ 100 identical exceptions (one per spring log):

Corrupted stdin stream in forked JVM 1. Stream '13: 50: 15.914 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiate the CacheAwareContextLoaderDelegate from the [Org.springframework.test.context.cache.DtelegateLext] class. java.lang.IllegalArgumentException: The stdin stream is corrupted. Expected comma after third character in command '13: 50: 15.914 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiate CacheAwareContextLoaderDelegate from class [Org.springframework.test.context.cache.DefaultCacheAwareDelegateLader]. at org.apache.maven.plugin.surefire.booterclient.output.ForkClient $ OperationalData. (ForkClient.java:469) at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.processLine (ForkClient.java:191) at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.consumeLine (ForkClient.java:158) at org.apache.maven.plugin surefire.booterclient.output.ThreadedStreamConsumer $ Pumper.run (ThreadedStreamConsumer.java:87) at java.lang.Thread.run (Thread.java:745)

Maven surefire plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.0.0-M6</version>
        </dependency>
    </dependencies>
</plugin>

      

+3


source to share


1 answer


IntelliJ links JUnit5, so IntelliJ and Maven are probably using different versions.

See JUnit5 docs about IntelliJ

Depending on which version of IntelliJ you are using, it is probably running an earlier version JUnit5

than what maven uses.

If you are on 2017.2

, you can try switching your dependency JUnit5

in yours pom.xml

to M4

and see if that resolves the incompatibility.

Also try specifying junit-jupiter-engine:5.0.0-M4

depending on the plugin in pom.xml

as well junit-platform-surefire-plugin

.

I use 5.0.0-M5

this way successfully .

[UPDATE 2017-08-10]: in regards to your comments, I am using spring boot 1.5.4.RELEASE

, so I cannot compare a similar comparison.

You don't say which version of IntelliJ you are using - if the tests are still running in IntelliJ, that version of the config is your target, presumably. View your maven project or debug the test output to get the classpath and see what versions are in use.

Spring probably manages a lot of versions for you. Are you using the parent pom spring-boot or depending on the dependencies spring-boot-starter

?



To see what is going on and which dependency spring is pulling in which dependency is broken JUnit5

, do

mvn dependency:tree

and go to the list of dependencies and versions to see exactly what you have on maven.

You may find that the versions you think were specified are being overridden and you have to put exceptions in the pom to stop this.

[UPDATE 2]: just a quick change - try putting the dependency junit-jupiter-engine

in a dependency block maven-surefire-plugin

next to junit-platform-surefire-provider

:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider
                    </artifactId>
                    <version>1.0.0-M5</version>
                </dependency>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.0.0-M5</version>
                </dependency>
            </dependencies>
        </plugin>

      

Note. I haven't been on the version yet 2.20

(and I am still on 5.0.0-M5

) - sorry, but I don't have time to try it this week.

You can also see tweak maven-surefire-plugin

config forkCount=0

to see if this message gives a better exception.

You can hide your project to the bare minimum and expose Jira issues with Maven and Spring testing . I changed the tags to your question to include spring-boot

so one of their guys can notice. Or maybe not, depending on your luck - I find they are more likely to respond if you read your stackoverflow @springboot url.

+2


source







All Articles