I'm using JUnit Categories and ClassPathSuite in a setup similar to that described in this answer. To recap:
public interface FastTests {
}
@RunWith(Categories.class)
@Categories.IncludeCategory(FastTests.class)
@Suite.SuiteClasses(AllTests.class)
public class FastTestSuite {
}
@RunWith(ClasspathSuite.class)
public class AllTests {
}
...where AllTests makes use of the ClasspathSuite library.
A test class that's part of the FastTests category would look like this:
@Category(FastTests.class)
public class StringUtilsTest {
// ...
}
When I run "FastTestSuite" in my IDE, all tests with the FastTests annotation are executed, nice & smooth:
Now, I want to do the same thing with Ant. (To my surprise, I couldn't easily find instructions for this on SO.) In other words, I need an Ant target that runs all tests with the FastTests annotation.
I've tried some simplistic approaches using <test>
or <batchtest>
...
<junit showoutput="true" printsummary="yes">
<test name="fi.foobar.FastTestSuite"/>
<formatter type="xml"/>
<classpath refid="test.classpath"/>
</junit>
... but no luck, so far.
Edit: Besides the IDE, it works fine with JUnitCore on the command line:
$ java -classpath "classes:WebContent/WEB-INF/lib/*" org.junit.runner.JUnitCore fi.foobar.FastTestSuite
.............
Time: 0.189
OK (13 tests)
unittest-fast: [junit] Running fi.foobar.FastTestSuite [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.053 sec [junit] Test fi.foobar.FastTestSuite FAILED
– NabalaTestcase: initializationError took 0.002 sec Caused an ERROR null at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
Btw, as I edited on the question, this works with JUnitCore, which seems encouraging... – Nabala