【发布时间】:2021-05-10 10:53:34
【问题描述】:
抱歉,如果该帖子重复了许多其他帖子,我已经看过所有帖子并尝试了所有建议的食谱,但问题仍然存在。
我有一个使用 Grails 构建的 SpringBoot 项目,结构如下:
mybike-rest
src
integration
java
com.bike
BorrowMyBikeApplicationTest
resources
main
java
...
test
java
...
我的build.gradle如下:
plugins {
id 'org.springframework.boot' version '2.4.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'idea'
}
group = 'java.bike'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '8'
sourceSets {
main {
java.srcDirs('./src/main/java')
resources.srcDirs('./src/main/resources')
}
test {
java.srcDirs('./src/test/java')
resources.srcDirs('./src/test/resources')
}
integrationTest {
java.srcDirs('./src/integration/java')
resources.srcDirs('./src/integration/resources')
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
configurations{
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntime.extendsFrom testRuntime
}
task integrationTest(type: Test) {
description = 'Runs the integration tests.'
group = 'verification'
outputs.upToDateWhen { false }
testLogging { events "passed", "skipped", "failed" } // This is not needed, but I like to see which tests have run
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
}
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.projectlombok:lombok'
compile 'org.flywaydb:flyway-core'
runtimeOnly 'org.postgresql:postgresql'
runtimeOnly 'com.h2database:h2'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.junit.jupiter:junit-jupiter'
testCompile 'org.springframework.data:spring-data-commons'
testCompile 'org.assertj:assertj-core'
integrationTestCompile sourceSets.main.output
integrationTestCompile sourceSets.test.output
integrationTestCompile configurations.compile
integrationTestCompile configurations.testCompile
integrationTestRuntime configurations.runtime
integrationTestRuntime configurations.testRuntime
integrationTestAnnotationProcessor configurations.testAnnotationProcessor
annotationProcessor 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
}
IntelliJ 正确识别我的测试:
但是,当我在 iJ 中运行测试时,我得到以下输出:
> Task :cleanIntegrationTest
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :compileTestJava UP-TO-DATE
> Task :processTestResources UP-TO-DATE
> Task :testClasses UP-TO-DATE
> Task :compileIntegrationTestJava UP-TO-DATE
> Task :processIntegrationTestResources
> Task :integrationTestClasses
> Task :integrationTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':integrationTest'.
> No tests found for given includes: [com.bike.BorrowMyBikeApplicationTest](filter.includeTestsMatching)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
8 actionable tasks: 3 executed, 5 up-to-date
当我在命令行中以gradlew clean iT -i 运行时,我看到以下输出:
...
> Task :compileIntegrationTestJava
file or directory '/home/nmilyaev/Work/Intellij/mybike-rest/src/integrationTest/java', not found
Excluding []
Excluding []
Caching disabled for task ':compileIntegrationTestJava' because:
Build cache is disabled
Task ':compileIntegrationTestJava' is not up-to-date because:
Output property 'destinationDirectory' file /home/nmilyaev/Work/Intellij/mybike-rest/build/classes/java/integrationTest has been removed.
Output property 'destinationDirectory' file /home/nmilyaev/Work/Intellij/mybike-rest/build/classes/java/integrationTest/com has been removed.
Output property 'destinationDirectory' file /home/nmilyaev/Work/Intellij/mybike-rest/build/classes/java/integrationTest/com/bike has been removed.
The input changes require a full rebuild for incremental task ':compileIntegrationTestJava'.
Full recompilation is required because no incremental change information is available. This is usually caused by clean builds or changing compiler arguments.
file or directory '/home/nmilyaev/Work/Intellij/mybike-rest/src/integrationTest/java', not found
Compiling with JDK Java compiler API.
Created classpath snapshot for incremental compilation in 0.006 secs. 1 duplicate classes found in classpath (see all with --debug).
:compileIntegrationTestJava (Thread[Daemon worker Thread 10,5,main]) completed. Took 0.643 secs.
:processIntegrationTestResources (Thread[Execution worker for ':' Thread 3,5,main]) started.
> Task :processIntegrationTestResources
file or directory '/home/nmilyaev/Work/Intellij/mybike-rest/src/integrationTest/resources', not found
Caching disabled for task ':processIntegrationTestResources' because:
Build cache is disabled
Task ':processIntegrationTestResources' is not up-to-date because:
Output property 'destinationDir' file /home/nmilyaev/Work/Intellij/mybike-rest/build/resources/integrationTest has been removed.
Output property 'destinationDir' file /home/nmilyaev/Work/Intellij/mybike-rest/build/resources/integrationTest/application.properties has been removed.
file or directory '/home/nmilyaev/Work/Intellij/mybike-rest/src/integrationTest/resources', not found
:processIntegrationTestResources (Thread[Execution worker for ':' Thread 3,5,main]) completed. Took 0.019 secs.
:integrationTestClasses (Thread[Execution worker for ':' Thread 3,5,main]) started.
> Task :integrationTestClasses
Skipping task ':integrationTestClasses' as it has no actions.
:integrationTestClasses (Thread[Execution worker for ':' Thread 3,5,main]) completed. Took 0.0 secs.
:integrationTest (Thread[Execution worker for ':' Thread 3,5,main]) started.
> Task :integrationTest
Excluding []
Caching disabled for task ':integrationTest' because:
Build cache is disabled
Task ':integrationTest' is not up-to-date because:
Task.upToDateWhen is false.
Finished generating test XML results (0.0 secs) into: /home/nmilyaev/Work/Intellij/mybike-rest/build/test-results/integrationTest
Generating HTML test report...
Finished generating test html results (0.003 secs) into: /home/nmilyaev/Work/Intellij/mybike-rest/build/reports/tests/integrationTest
:integrationTest (Thread[Execution worker for ':' Thread 3,5,main]) completed. Took 0.149 secs.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.8.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 4s
老实说,我在月球下尝试了所有方法,但有些不对劲。谁能帮我找出我错过了什么?
【问题讨论】:
标签: java spring-boot gradle integration-testing