I never used a logging mechanism before, but now I have requirement to log the results of my JUnit tests to a file.
I want to log the result of below test (whether pass, fail or throw exception) to a log file.
@Test
public void statusCode200() {
Assert.assertEquals("Java class".getStatusCode(), 200);
}
Can someone please advise how to achieve this?
From the comments:
I am currently using this logging mechanism: – ginny singh 22 mins ago
fileHandler = new FileHandler(System.getProperty("user.dir")+"//ExecutionResults.log");
simpleFormatter = new SimpleFormatter();
StreamHandler sh = new StreamHandler(System.out, simpleFormatter);
log.setUseParentHandlers(false);
log.addHandler(sh);
log.addHandler(fileHandler);
fileHandler.setFormatter(simpleFormatter);
fileHandler.setLevel(Level.ALL);
log.setLevel(Level.ALL);
log.config("Logger Configuration done.");
fileHandler.close();