繁体   English   中英

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

[英]IntelliJ Spring Gradle “Run all tests” not working (single test runs fine)

我有一个带有4个测试的Spring Gradle项目和以下build.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")
}

我可以使用“运行测试”开始每个测试并且它工作得很好但是当我尝试“运行所有测试”时它失败并显示消息“错误运行”所有“:No junit.jar”

我已经尝试添加以下任何依赖项,但没有解决问题:

testCompile 'junit:junit:4.12


testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.2')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.2')

我正在使用IntelliJ

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

另外,我想检查IntelliJ IDE中的测试运行器配置。 打开“首选项或设置”对话框窗口。 检查Gradle配置并查找Build,Execution,Deployment | 构建工具| Gradle | 亚军:

在此输入图像描述

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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