java - How to create JUNIT Reports using runlistener? -


I am using JUNIT for my test but I am able to run my test but The problem is how do I programmatically make Junich reports using the runlistener? ( Without using AN or MAVEN ) I am a little overwhelmed and appreciate any guidance for this.

Implementation of the listener: -

  Junitak junit = new geotitcore (); Junit.ed Listener (new MyJunist Listener ()); Junit.run (AllEJBJunitTests.class);   

How do I proceed with the report creation?

You can generate HTML reports using StringBuffer.

  string filePath = "file path where you want to keep your report"; String report filename = "myReport.htm"; Junitak junit = new giantitcore (); Junit.ed Listener (new MyJunist Listener ()); Results Result = Jr.Run (AllEJBJunitTests.class); StringBuffer myContent = getResultContent (result, size); // Size represents the number of AllEJBJunitTests class, if you think 5 EJB categories are then size 5. writeReportFile (filepath + "/" + reportFileName, myContent);   

// This method will give you HTML content.

  Private StringBuffer getResultContent (Results Results, numberOfTestFiles int) {int numberOfTest = result.getRunCount (); Int numberoffastfile = results; gatefilter (); Int numbersoffact ignore = results. Gate ignore count (); Int numberAufastAssistance = numberoffest - numberoffastfile - number ooftext ignored; Int successPercent = (numberOfTest! = 0)? Number of OftestSecurity * 100 / NumberOfTest: 0; Double time = result GetRunTime (); StringBuffer myContent = New StringBuffer ("& lt; h1> Junitee Test Report & lt; / h1 & gt; & lt; h2 & gt; Results & lt; / h2 & gt; & lt; Table border = \" 1 \ "& gt; & lt; tr & gt; & lt; th & gt; Test Files & lt; / th & gt; & lt; th & gt; Test & lt; / th & gt; & lt; Th & Gt; success & lt; / th & gt; "); If (meditation on numberOfTestFail> 0) || {myContent.append ("& lt; th> failure   th & gt; Do not give & lt; / th & gt; "); } MyContent.append ("& lt; th> Test Time (sec)  & lt; / tr & gt; & lt; tr '); if ((numberOfTestFail> 0) MyContent.append ("& gt; & lt; TD & gt;"); myContent.append myContent.append ("& lt; / td> gt; TD & gt; "); myContent.append (successPercent); myContent.append ("%   "); if ((numberoffastfile> gt; 0) || ( MyContent.append (numberOfTestFail); myContent.append ("& lt; / td> ;); myContent.append (numberOfTestIgnore); myContent.append ( "& Lt; / td & gt; & lt; td & gt; ");} MyContent.append (Double.valueOf (time / 1000.0D)); myContent.append (" & lt; / td>    

// This particular report will be created in the directory that you have mentioned.

  Private Zero writeReportFile (string file name, StringBuffer reportContent) {FileWriter MyFileWriter = Faucet; {MyFileWriter = Try New FileWriter (fileName); MyFileWriter.write (reportContent.toString ()); } Hold (IOException E) {} Finally {if (myFileWriter! = Null} {try {myFileWriter.close (); } Catch (IOException E) {}}}}   

Cheers !!

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -