【问题标题】:run single integration test with gradle使用 gradle 运行单个集成测试
【发布时间】:2013-08-06 08:57:35
【问题描述】:

我正在尝试使用 gradle 的 -Dtest.single 标志运行单个集成测试。我添加了另一个源集src/integrationTest 并将测试放在那里。我有一个集成测试任务

task integrationTests(type: Test) {
    dependsOn 'assemble', 'integrationTestClasses'    
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
}

这运行良好,但如果我尝试运行单个测试,它会告诉我找不到匹配的测试。我不想在每次编写新测试时都运行每个集成测试。有没有办法做到这一点?

【问题讨论】:

    标签: testing integration gradle


    【解决方案1】:

    从 Gradle 1.10 开始,您可以编写:

     //select specific test method
    gradle test --tests org.gradle.SomeTest.someFeature
    
    //select specific test class
    gradle test --tests org.gradle.SomeTest
    
    //select all tests from package
    gradle test --tests org.gradle.internal*
    
    //select all ui test methods from integration tests by naming convention
    gradle test --tests *IntegTest*ui*
    
    //selecting tests from different test tasks
    gradle test --tests *UiTest integTest --tests *WebTest*ui
    

    在这里阅读更多 http://www.gradle.org/docs/1.10/release-notes#executing-specific-tests-from-the-command-line

    【讨论】:

    • 嵌入式链接或评论都提到这是否适用于 OP 询问的集成测试。
    【解决方案2】:

    正确的语法是:

    gradle testTaskName -DtestTaskName.single=...

    在这种情况下:

    gradle integrationTest -DintegrationTest.single=...

    【讨论】:

    • 当我尝试这个时,我得到类似:$ gradlew -Dtest.single=SingleTest :subproject:test ... :buildSrc:test FAILED FAILURE: Build failed with an exception. What went wrong: Execution failed for task ':test'. Could not find matching test for pattern: SingleTest
    • 也许你没有同名的测试类?
    • 我发现 -Dtest.single='foo' 在 linux 上没问题,但由于使用 ' vs " 或什么都没有在 win 上失败。因此,这些选择可能会因使用的 shell 而产生影响.
    • 其实应该是-DintegrationTest.single=...(不带“s”)
    • 其实应该是 -DintegrationTests.single=... 因为他在他的 gradle 文件中将任务命名为“integrationTests”。
    【解决方案3】:

    以防有人来这里寻找答案。这已在 gradle 5.0 中删除。在https://docs.gradle.org/current/userguide/upgrading_version_4.html中寻找test.single

    如果您仍希望以这种方式使用命令行选项,您应该可以使用--tests 命令行参数。见https://docs.gradle.org/current/userguide/java_testing.html#simple_name_pattern

    $ ./gradlew integrationTest --tests=MyTest
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      • 2015-09-05
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 2018-06-23
      相关资源
      最近更新 更多