When a given JUnit4 test runs, I want it to generate a logfile of all of its TestResults. I do not want to invoke this via CI/ant/maven. I want this to run anytime the JUnit test is called from anywhere. If that is not possible, then I would like to write my own runner which problematically invokes my AllTestSuites class and logs all the results itself.
Here would be one of my test classes:
public class SimpleTestSuite extends TestCase{
@Test
public void simpleTestPass() {
assertTrue(true);
}
@Test
public void simpleTestFail() {
assertTrue(false);
}
@Test
public void simpleTestException() {
throw new RuntimeException();
}
}
I included it in a TestSuite, which contains all of my test Suites to run:
@RunWith(Suite.class)
@Suite.SuiteClasses({SimpleTestSuite.class, ExampleSuite.class,})
public final class AllTestSuites {}
I want to invoke AllTestSuites and have it generate a log file such as below. Remember, I prefer to capture what is on the JUnit4 framework’s result bus, and not to reinvent/create a new test runner.
simpleTestPass - pass - 1/1 assertions passed
simpleTestFail - fail - 0/1 assertions passed
simpleTestException - exception - stacktrace as follows...
Add logger in you Test Class and Base Test Class and define as
TestWatchManas below: