我目前正在尝试为我的春季启动rest服务实现JUnit5测试。我还找到了一个很有前途的教程,但我遇到了一个错误。
教程:https://howtoprogram.xyz/2017/09/12/junit-5-spring-boot-example/
与教程相比,我使用的是Gradle。我的秤看起来是这样的:
dependencies {
compile "com.google.code.gson:gson:2.8.0"
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
exclude group: "com.fasterxml.jackson.core"
}
compile("org.springframework.boot:spring-boot-starter-jetty")
compile("io.springfox:springfox-swagger2:2.7.0")
// reroute default logs
compile "ch.qos.logback:logback-classic:1.2.3"
compile "ch.qos.logback:logback-core:1.2.3"
// json logs:
compile "net.logstash.logback:logstash-logback-encoder:4.9"
// junit
testCompile("org.junit.jupiter:junit-jupiter-api:5.0.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.0.0")
// junit for spring-boot
testCompile("org.springframework.boot:spring-boot-starter-parent:1.5.7.RELEASE")
testCompile("org.springframework.boot:spring-boot-starter-test")//:1.5.7.RELEASE")
{
// exclude JUnit 4 support
exclude group: "junit"
}
testCompile("org.junit.platform:junit-platform-engine:1.0.0-M5")
testCompile("org.junit.platform:junit-platform-launcher:1.0.0-M5")
}我无法找到如何将Maven脚本的测试应用于我的gradle脚本。
另外,我在构建
/home/udev/prj/research/java-unittest/src/test/java/one/utest/HelloControllerTest.java:6: error: package org.springframework
.test.context.junit.jupiter does not exist
import org.springframework.test.context.junit.jupiter.SpringExtension;
^
/home/udev/prj/research/java-unittest/src/test/java/one/utest/HelloControllerTest.java:9: error: cannot find symbol
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
^
symbol: class SpringBootTest
/home/udev/prj/research/java-unittest/src/test/java/one/utest/HelloControllerTest.java:13: error: cannot find symbol
private TestRestTemplate restTemplate;
^
symbol: class TestRestTemplate
location: class HelloControllerTest
/home/udev/prj/research/java-unittest/src/test/java/one/utest/HelloControllerTest.java:8: error: cannot find symbol
@ExtendWith(SpringExtension.class)
^
symbol: class SpringExtension
/home/udev/prj/research/java-unittest/src/test/java/one/utest/HelloControllerTest.java:12: error: cannot find symbol
@Autowired
^
symbol: class Autowired
location: class HelloControllerTest
5 errors
:compileTestJava FAILED发布于 2017-09-28 08:52:19
您的教程讨论了spring starter父版本2.0.0.BUILD-快照,但是您使用的是1.5.7.RELEASE版本,在该版本中还没有Junit 5支持。
我不知道Maven script's test是什么意思,但是如果您指的是范围测试,那么在Gradle中,您只需使用testCompile或testRuntime来获得相同的效果。
https://stackoverflow.com/questions/46464396
复制相似问题