Next, the methods in Testmain are analyzed individually:
The first is Htmlfile. Java, which is used in the Main method:
New htmlfile (); Hf.createlog ("c:/code/1.html");
Look at the name to know, in fact, the realization of something very simple is to create 1.html as a log output file.
The specific implementation code is as follows:
Public classHtmlfileImplementsIFile {PrivateFilehandler Filehandler; PrivateLogger Logger = Logger.getlogger (htmlfile.class. GetName ()); @Override Public voidWrite (String p_info) {//TODO auto-generated Method Stub} @Override Public voidCreatelog (String p_info) {//TODO auto-generated Method Stub//String P_info is the file path Try{Filehandler=NewFilehandler (P_info); } Catch(SecurityException e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } filehandler.setformatter (NewHtmlformatter ()); Logger.addhandler (Filehandler); } @Override Public voidCloselog () {//TODO auto-generated Method StubFilehandler.close (); Recordstore.p_pass= 0; Recordstore.p_fail= 0; Recordstore.result= ""; Recordstore.expected= ""; Recordstore.actual= ""; Recordstore.instruction= ""; RECORDSTORE.I= 0; } @Override Public voidWrite (String p_info1, String P_info2) {//TODO auto-generated Method Stub} @Override PublicString Read () {//TODO auto-generated Method Stub return NULL; } @Override Publicstring Read (string p_info) {//TODO auto-generated Method Stub return NULL; } @Override Publicstring Read (string p_info1, String P_info2) {//TODO auto-generated Method Stub return NULL; } @Override Public voidwrite (Object P_info1, Object P_info2, Object P_info3) {//TODO auto-generated Method Stub//When overriding a method, the first value is the case description, the second is the actual result, and the third is whether the identity succeedsrecordstore.i++; Recordstore.instruction=(String) p_info1; Recordstore.actual=P_info2; if(P_info1! =NULL&& P_info2! =NULL&& p_info1! = "") { if("True". Equalsignorecase ((String) P_info3)) {Recordstore.result= "True"; Recordstore.p_pass++; }Else{Recordstore.result= "False"; Recordstore.p_fail++; } logger.info (String) p_info1); } }}
Explain:
1. Because of this class, implements the method of the IFile interface, and ifile just defines the different methods of writing, reading, and creating files. So this is just for better compatibility after the output of the different log format, there is nothing much to use.
2. Implement the Createlog method by manually entering "FilePath" to create an HTML file to save the file.
Note the following code:
Filehandler.setformatter (new htmlformatter ());
Because it is the use of HTML format to output statistical reports, so you need to use the Setformatter method, and Java is the original for the INI, or the properties format of the file format, so you need to re-write a format for the HTML class. namely Htmlformatter ();
3. Implement the Closelog () method, the first is to close the file system, in addition to the need to erase all records.
4. Implement the Write () method and put some information into the recordstore. The rest of the information, written in log
Interface testing-automated-java implementation-htmlfile