I was shocked to discover that this issue was first reported a few years ago here , and it is still uncertain when Ant will fix it. Fortunately, is the one that saves my purposes of migrating all the tests into junit 4.
Here is an example of how we can create a suite runner to run multiple tests or test suites. The purpose of this suite runner is to generate xml-based test reports that will be stored onto specified folder such that Teamcity can then import these report data from "Ant JUnit" format from the specified folder.
public class SomeSuiteRunner { public static void main() throws Exception { boolean success = new SomeSuiteRunner().run(); System.exit(success ? 0 : 1); } public boolean run() throws Exception { File reportDirectory = new File("/reports"); org.apache.commons.io.FileUtils.deleteDirectory(reportDirectory); reportDirectory.mkdirs(); return runTests(); } private boolean runTests() throws Exception { boolean isSuccessful = true; final Class testClass = this.getClass().getClassLoader().loadClass("package.ATest"); return runTestClass(testClass); } private boolean runTestClass(Class testClass) { JUnitCore runner = new JUnitCore(); final XmlWritingListener listener = new XmlWritingListener("/reports"); runner.addListener(listener); listener.startFile(testClass); try{ return runner.run(testClass); } finally { listener.closeFile(); } } }
To be able to show the number of @Ignore tests on Teamcity, we need to config our project on Teamcity properly (in "Runner" settings):
- choose an appropriate "Build runner"
- choose "Ant JUnit" as the "Import data from XML"
- tpye, for example, "/reports/*.xml" in the "Report paths"