java - 使用 Maven 的命名约定在 Gradle 中进行集成测试?
问题描述
来自 Maven,我正在探索 Gradle 作为替代方案。技术:Java 11、jUnit 5、Maven 3.6、Gradle 5.6。
我一直在配置集成测试。遵循 Maven 的 Surefire 和 Failsafe 插件的默认命名约定,我的测试位于标准测试目录中,并通过它们的后缀进行区分:单元测试以 . 结尾Test.java
,集成测试以IT.java
.
是否可以在 Gradle 中进行相同的设置?到目前为止,我已经看到了两种方法:
- 使用 jUnit5 的标签(这意味着我必须去标记每个集成测试)
- 为单元测试和集成测试使用单独的目录
理想情况下,我想保持我的文件夹结构不变,因为它会影响多个 git 存储库。
解决方案
好的,感谢Lukas和Slaw的反馈,我想我设法让它与源集一起工作。
请让我知道这是否可以改进:
// define the dependencies of integrationTest, inherit from the unit test dependencies
configurations {
integrationTestImplementation.extendsFrom(testImplementation)
integrationTestRuntimeOnly.extendsFrom(testRuntimeOnly)
}
sourceSets {
test {
java {
// exclude integration tests from the default test source set
exclude "**/*IT.java"
}
}
// new source set for integration tests
integrationTest {
// uses the main application code
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
java {
// the tests are at the same directory (or directories) as the unit tests
srcDirs = sourceSets.test.java.srcDirs
// exclude the unit tests from the integration tests source set
exclude "**/*Test.java"
}
resources {
// same resources directory (or directories) with the unit tests
srcDirs = sourceSets.test.resources.srcDirs
}
}
}
// define the task for integration tests
task integrationTest(type: Test) {
description = "Runs integration tests."
group = "verification"
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
shouldRunAfter test
// I'm using jUnit 5
useJUnitPlatform()
}
// make the check task depend on the integration tests
check.dependsOn integrationTest
推荐阅读
- javascript - 如何更改 jQuery Skitter.js 幻灯片的宽度?
- javascript - 如何将数据从对话框传回angularjs中的控制器?
- javascript - 如何在反应原生中调整 webview 中的一些 javascript?
- php - 将 PHP 5.6 升级到 7.1 时 PHP PDO ODBC 扩展出现问题
- spring - 如何回滚一种方法并在测试中提交第二种方法
- python - 在递归函数中附加一个带有列表的空列表
- c# - wpf根据孩子缩放画布宽度
- python - PyQt 上一个 GUI 框架的“后退”按钮的适当功能
- c# - 尝试在 Visual Studio 2015 中构建使用 Visual Studio 2017 构建的 Web 应用程序时出错
- cron - Elixir:第一次调用后未运行 Mix 任务的计划作业