Based on How to specify @category in test task in gradle?
I want to have 2 different test tasks:
test
for the fast teststestLongRunning
for the fast and the slow tests.
I have successfully modified the buildin task test
in a way that the "SlowTest"-s are onmitted:
org.namespace.some.MySlowTestClass#someReallyLongRunningTest
is not executed as desired when executing task "test"
My question: Is it possible to add an additional gradle task "testLongRunning" that executes all tests (including org.namespace.some.MySlowTestClass#someReallyLongRunningTest
) while the gradle task "test" does not excute the slow one?
My working example thas skips SlowTest
looks like this:
// 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(){
}
}
what i have tried:
when i add this to subproject/build.gradle
// this is line 65
task testLongRunning (type: test){
dependsOn test
useJUnit {
includeCategories 'org.junit.SlowTest'
}
}
i get this error
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