예제 #1
0
 protected static String getMethodName(ITestResult tr) {
   String method_name = tr.getName();
   Object[] params = tr.getParameters();
   if (params != null && params.length > 0) {
     String tmp = null;
     if (params[0] instanceof Class<?>) tmp = ((Class<?>) params[0]).getSimpleName();
     else if (params[0] != null) tmp = params[0].getClass().getSimpleName();
     if (tmp != null) method_name = method_name + "-" + tmp;
   }
   return method_name;
 }
 private void write2LogFile(ITestResult iTestResult, File testFolder) {
   BufferedWriter out = null;
   try {
     if (testFolder == null) {
       LogUtils.log("Can not write to file test folder is null");
       return;
     }
     String output = SGTestNGReporter.getOutput();
     if (StringUtils.isEmpty(output)) {
       LogUtils.log("nothing to write to log file");
       return;
     }
     String parameters = TestNGUtils.extractParameters(iTestResult);
     File testLogFile =
         new File(
             testFolder.getAbsolutePath()
                 + "/"
                 + iTestResult.getName()
                 + "("
                 + parameters
                 + ").log");
     if (!testLogFile.createNewFile()) {
       LogUtils.log(
           "Failed to create log file ["
               + testLogFile
               + "];\n log output: "
               + Reporter.getOutput());
       return;
     }
     FileWriter fstream = new FileWriter(testLogFile);
     out = new BufferedWriter(fstream);
     out.write(output);
   } catch (Exception e) {
     LogUtils.log("Failed to write to log file result - " + iTestResult, e);
   } finally {
     SGTestNGReporter.reset();
     if (out != null) {
       try {
         out.close();
       } catch (IOException e) {
         LogUtils.log("Failed closing stream", e);
         // ignore
       }
     }
   }
 }