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)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…