:gradle這個JUnit的類別與不同類別的附加testtask基於</p> <p>我想有2個不同的測試任務
test
爲快速測試testLongRunning
的快和慢的測試。
我已成功修改了的buildin任務test
的方式,將「SlowTest」 -s是onmitted:
org.namespace.some.MySlowTestClass#someReallyLongRunningTest
不執行爲執行任務「測試」
我的問題時所需的:是否有可能添加一個額外的gradle任務「testLongRunning」執行所有測試(包括org.namespace.some.MySlowTestClass#someReallyLongRunningTest
),而gradle任務「測試」不執行慢的任務?
我的工作例如全髖關節置換跳過SlowTest
看起來是這樣的:
// subproject/build.gradle
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.11'
}
test {
useJUnit {
excludeCategories 'org.junit.SlowTest' // userdefined interface in "subproject/src/test/java/org/junit/SlowTest.java"
}
}
// subproject/src/test/java/org/junit/SlowTest.java
package org.junit;
// @Category see https://stackoverflow.com/questions/38872369/cannot-include-exclude-junit-tests-classes-by-category-using-gradle
public interface SlowTest {
/* category marker for junit
via @Category(org.junit.SlowTest.class) */
}
// subproject/src/test/org/namespace/some/MySlowTestClass.java
package org.namespace.some;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.experimental.categories.*;
public class MySlowTestClass {
// @Category see https://stackoverflow.com/questions/38872369/cannot-include-exclude-junit-tests-classes-by-category-using-gradle
@Category(org.junit.SlowTest.class)
@Test
public void someReallyLongRunningTest(){
}
}
我曾嘗試:
當我加入這子項目/的build.gradle
// this is line 65
task testLongRunning (type: test){
dependsOn test
useJUnit {
includeCategories 'org.junit.SlowTest'
}
}
我得到這個錯誤
FAILURE: Build failed with an exception. * Where: Build file '...\subproject\build.gradle' line: 66 * What went wrong: A problem occurred evaluating project ':subproject'. > org.gradle.api.tasks.testing.Test_Decorated cannot be cast to java.lang.Class