为了账号安全,请及时绑定邮箱和手机立即绑定

IntelliJ Spring Gradle“运行所有测试”不起作用(单个测试运行良好)

IntelliJ Spring Gradle“运行所有测试”不起作用(单个测试运行良好)

墨色风雨 2023-03-23 15:03:19
我有一个带有 4 个测试和以下 build.gradle 的 Spring Gradle 项目:plugins {    id 'org.springframework.boot' version '2.1.6.RELEASE'    id 'java'}apply plugin: 'io.spring.dependency-management'version = '0.0.1'sourceCompatibility = '11'configurations {    compileOnly {        extendsFrom annotationProcessor    }}repositories {    mavenCentral()}dependencies {    implementation 'org.springframework.boot:spring-boot-starter'    //Rest Controller    compile 'org.springframework.boot:spring-boot-starter-web'    //Lombok    compileOnly 'org.projectlombok:lombok'    annotationProcessor 'org.projectlombok:lombok'    //Tests    testImplementation 'org.springframework.boot:spring-boot-starter-test'    testCompile 'com.h2database:h2'    //Database    compile("mysql:mysql-connector-java")    compile("org.springframework.boot:spring-boot-starter-data-jpa")    //Authentication    compile 'org.springframework.security:spring-security-crypto' //e.g. PasswordEncoder    compile 'org.springframework.boot:spring-boot-starter-security' //e.g. @PreAuthorize    //ResourceAssembler    compile 'org.springframework.boot:spring-boot-starter-hateoas'    //JWT Token generation    compile("com.auth0:java-jwt:3.4.0")}我可以用“运行测试”开始每个测试,它工作得很好,但是当我尝试“运行所有测试”时,它失败并显示消息“运行“全部”时出错:没有 junit.jar”我已经尝试添加以下任何依赖项,但都没有解决问题:testCompile 'junit:junit:4.12testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.2')testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.2')我正在使用 IntelliJ
查看完整描述

1 回答

?
冉冉说

TA贡献1877条经验 获得超1个赞

类路径派生自包含测试的模块的依赖项。这些文件是从工作目录加载的,因此应该在测试的运行/调试配置中指定它。以下链接解释了如何为您的测试配置它。 在 IntelliJ 中运行 JUnit 测试

另外,我想检查 IntelliJ IDE 中的测试运行器配置。打开首选项或设置对话框窗口。检查 Gradle 配置并查找构建、执行、部署 | 构建工具 | 摇篮 | 亚军:

//img1.sycdn.imooc.com//641bf9da00011b5b06590546.jpg

在这里,选择 Gradle 测试运行器。配置完成后,您可以使用覆盖率运行您的代码,看看它是否有帮助。



查看完整回答
反对 回复 2023-03-23
  • 1 回答
  • 0 关注
  • 70 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信