I have an ant build file that contains JUnit test suite that I would like to execute. Currently I just right click and run the build file from Eclipse.
I want to write a java code that can execute the ant build file automatically. So I just run the code and ant will be executed.
Second is I want to capture the test result. Currently the result is based on JUnit HTML report. I want to make my own simple test report. I read there is JUnitResultFormatter but I can't find the instructional step by step how to use it. Can anyone point me the reference?
The easiest way to do that is to use the JunitCore
class from java. It is not advised to call the main
from ant directly, see the Junit Faq, and http://www.answerspice.com/c119/1497833/how-do-i-run-junit-tests-from-inside-my-java-application.
It is very common to define a main like this for each test case, to be able to run the tests individually from command line. I usually also change the logging settings in those methods, to get more information when I run a single test manually than from within ant.
In order then to create a custom report, you will have to implement a RunListener
that creates your report, and register it, as described in the javadoc:
public void main(String... args) {
JUnitCore core= new JUnitCore();
core.addListener(new RingingListener());
core.run(MyTestClass.class);
}
Your listener will then be called before and after each test run, and passed descriptive information about the test that is about to run, and how the test went once it is done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With