2016-11-08 64 views
0

我想通過gradle文件運行我的junit測試,但構建成功但未運行任何測試。這是我的gradle這個文件看起來像:Gradle文件未運行測試

apply plugin: 'java' 

// Creating a new sourceSet because you should move your integration tests to a separate directory. 
sourceSets { 
    test { 
      java.srcDirs = ['src/integration-test/java'] 
     } 
      integrationTest { 
      java.srcDirs = ['src/integration-test/java']   
      compileClasspath += main.output + test.output 
      runtimeClasspath += main.output + test.output 
    } 
} 

configurations { 
    integrationTestCompile.extendsFrom testCompile 
    integrationTestRuntime.extendsFrom testRuntime 
} 



task integrationTest(type: Test, description: 'Runs the integration tests', group: 'Verification') { 
      testClassesDir = sourceSets.integrationTest.output.classesDir 
      classpath = sourceSets.integrationTest.runtimeClasspath 
      } 

運行的任務integrationTest之後,成功打造運行,但它不運行任何測試。有誰知道爲什麼?

+0

您需要定義一個'集成 - test' [來源集(https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_project_layout) –

回答

1

不知道你想做什麼:分開的完全移動的測試類的其他文件夾中的集成測試,但我認爲你需要包括測試配置的像這樣的依存關係:

configurations { 
    integrationCompile.extendsFrom testCompile 
    integrationRuntime.extendsFrom testRuntime 
} 

對於例如集成測試配置:

sourceSets { 
    test { 
     java.srcDirs = ['src/test/java'] 
    } 
    integration { 
     java.srcDirs = ['src/integration/java'] 
     resources.srcDir 'src/integration/resources' 
     compileClasspath += main.output + test.output 
     runtimeClasspath += main.output + test.output 
    } 
} 

configurations { 
    integrationCompile.extendsFrom testCompile 
    integrationRuntime.extendsFrom testRuntime 
} 

task integration(type: Test, group: 'Verification') { 
    testClassesDir = sourceSets.integration.output.classesDir 
    classpath = sourceSets.integration.runtimeClasspath 
} 

如果您只是想將你的測試,在其他文件夾(src/integration-test/java),並與test任務中,你可以使用下面的配置中運行他們的情況:

sourceSets { 
    test { 
     java.srcDirs = ['src/integration-test/java'] 
    } 
} 
+0

喜@alex爲感謝您回答。你可以看看我更新的答案 – Gaurav

+0

@Gaurav你確定集成在'src/test/resources'中的測試資源可能需要從'java.srcDirs = ['src/test/resources']'更改爲'java .srcDirs = ['src/test/java']'... –

+0

我將其更改爲resources.srcDirs,仍然沒有運行 – Gaurav