简体   繁体   中英

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

I have a Spring Gradle Project with 4 Tests and the following 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")
}

I can start every test with "Run test" and it works great but when I try to "Run all tests" it fails with the message "Error running "All": No junit.jar"

I already tried adding any of the following dependencies but none resolved the issue:

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')

I am using IntelliJ

The classpath is derived from the dependencies of the module containing the test. The files are loaded from the working directory so it should be specified in the Run/Debug configuration for your tests. The following link explains how to configure it for your tests. Running JUnit tests in IntelliJ

Also, I would want to check the test runner configuration in the IntelliJ IDE. Open the Preferences or Settings dialog window. Inspect the Gradle configuration and look for Build, Execution, Deployment | Build Tools | Gradle | Runner:

在此输入图像描述

Here, select the Gradle test runner. Once configured, you can run your code with coverage and see if it helps.

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