title: How to log results of JUnit test to a file?
body: <p>I never used a logging mechanism before, but now I have requirement to log the results of my JUnit tests to a file. </p>
  
  <p>I want to log the result of below test (whether pass, fail or throw exception) to a log file.</p>
  
  <pre><code>@Test
  public void statusCode200() {
      Assert.assertEquals("Java class".getStatusCode(), 200);
  }
  </code></pre>
  
  <p>Can someone please advise how to achieve this?</p>
  
  <hr>
  
  <p>From the comments:</p>
  
  <p>I am currently using this logging mechanism: –  ginny singh 22 mins ago</p>
  
  <pre><code>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();
  </code></pre>