【问题标题】:IntelliJ Spring Gradle "Run all tests" not working (single test runs fine)IntelliJ Spring Gradle“运行所有测试”不起作用(单个测试运行良好)
【发布时间】:2019-07-14 06:33:58
【问题描述】:

我有一个带有 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.12


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

我正在使用 IntelliJ

【问题讨论】:

  • 你可以使用 gradlew clean build 命令运行 gradle 吗?
  • 是的,但我不确定在使用该命令运行测试时是否可以看到代码覆盖率?

标签: java spring testing gradle intellij-idea


【解决方案1】:

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

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

在这里,选择 Gradle 测试运行器。配置完成后,您可以在覆盖范围内运行代码,看看是否有帮助。

【讨论】:

  • 非常感谢!!!这正是错误的设置,从“Platform Test Runner”更改为“Gradle Test Runner”后一切正常:D
猜你喜欢
  • 1970-01-01
  • 2019-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-16
  • 1970-01-01
  • 2018-08-19
  • 1970-01-01
相关资源
最近更新 更多