简体   繁体   中英

Is there conflict in this Maven pom.xml?

I'm using spring-boot-starter-parent 2.0.2.RELEASE, InteliJ IDEA, Java 11.

I'm trying to write a basic junit test for rest service but its not working (for the hellocontroller ) Am I missing any annotation in the junit test? OR Is there any conflict in my pom.xml? (especially in junit and spring )

Whenever I try to run the junit test (on IDEA) it returns fail. So I'd like to review conflict first.

The conflict I got is

Exception in thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.parseFullyQualifiedMethodName(Ljava/lang/String;)[Ljava/lang/String;
    at org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(DiscoverySelectors.java:366)
    at com.intellij.junit5.JUnit5TestRunnerUtil.createSelector(JUnit5TestRunnerUtil.java:206)
    at com.intellij.junit5.JUnit5TestRunnerUtil.buildRequest(JUnit5TestRunnerUtil.java:113)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)

JUnit test is:

import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import static org.hamcrest.EasyMock2Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = {HelloController.class})
public class TestwithJunit4 {

    @Autowired
    private HelloController controller;
    private MockMvc mvc;

    @Test
    public void contextLoads() throws Exception {
        mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk()).andExpect(content().string(equalTo("Hello World!")));
    }
}

And the maven dependency tree is:

NFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.0.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.0.2.RELEASE:compile
[INFO] |  |  \- org.springframework.boot:spring-boot-starter-logging:jar:2.0.2.RELEASE:compile
[INFO] |  |     +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |     |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |     +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |     |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] |  |     \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.0.2.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.12.0:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.12.0:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.9.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  +- org.springframework:spring-web:jar:5.0.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.0.6.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.0.2.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:2.0.2.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.0.2.RELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.4.0:test
[INFO] |  |  +- net.minidev:json-smart:jar:2.3:test
[INFO] |  |  |  \- net.minidev:accessors-smart:jar:1.2:test
[INFO] |  |  |     \- org.ow2.asm:asm:jar:5.0.4:test
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  +- org.assertj:assertj-core:jar:3.9.1:test
[INFO] |  +- org.mockito:mockito-core:jar:2.15.0:test
[INFO] |  |  +- net.bytebuddy:byte-buddy:jar:1.7.11:test
[INFO] |  |  +- net.bytebuddy:byte-buddy-agent:jar:1.7.11:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.6:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] |  \- org.xmlunit:xmlunit-core:jar:2.5.1:test
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:2.0.2.RELEASE:runtime (optional) 
[INFO] |  +- org.springframework.boot:spring-boot:jar:2.0.2.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.2.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.2.RELEASE:compile
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.31:compile
[INFO] |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.31:compile
[INFO] |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.31:compile
[INFO] +- org.apache.tomcat.embed:tomcat-embed-jasper:jar:9.0.40:compile
[INFO] |  \- org.eclipse.jdt:ecj:jar:3.18.0:compile
[INFO] +- org.springframework:spring-core:jar:5.0.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-jcl:jar:5.0.6.RELEASE:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.0.1:compile
[INFO] +- javax:javaee-api:jar:7.0:compile
[INFO] |  \- com.sun.mail:javax.mail:jar:1.6.1:compile
[INFO] |     \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.springframework:spring-beans:jar:5.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:5.0.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:5.0.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:5.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:5.0.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-jdbc:jar:5.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:5.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:5.0.6.RELEASE:test
[INFO] +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.12.0:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.0:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.12.0:compile
[INFO] +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.12.0:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.20:provided
[INFO] +- junit:junit:jar:4.11:test
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.2.0:compile
[INFO] |  +- org.apiguardian:apiguardian-api:jar:1.0.0:compile
[INFO] |  +- org.opentest4j:opentest4j:jar:1.1.0:compile
[INFO] |  \- org.junit.platform:junit-platform-commons:jar:1.2.0:compile
[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.2.0:test
[INFO] |  \- org.junit.platform:junit-platform-engine:jar:1.2.0:test
[INFO] +- org.junit.platform:junit-platform-runner:jar:1.2.0:test
[INFO] |  +- org.junit.platform:junit-platform-launcher:jar:1.2.0:test
[INFO] |  \- org.junit.platform:junit-platform-suite-api:jar:1.2.0:test
[INFO] +- org.hamcrest:hamcrest-junit:jar:2.0.0.0:compile
[INFO] |  \- org.hamcrest:java-hamcrest:jar:2.0.0.0:compile
[INFO] +- org.hamcrest:hamcrest-all:jar:1.3:compile
[INFO] +- org.hamcrest:hamcrest-library:jar:1.3:compile
[INFO] +- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] \- org.testng:testng:jar:6.1.1:compile
[INFO]    +- org.beanshell:bsh:jar:2.0b4:compile
[INFO]    +- com.beust:jcommander:jar:1.12:compile
[INFO]    \- org.yaml:snakeyaml:jar:1.19:compile

You are using JUnit4 and JUnit 5 in one test. Two engines in one class are not supported by the junit. Remove one of them and use only JUnit 4 or JUnit 5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM