2016-01-14 72 views
1

在這裏,我試圖打印測試結果... 但無論我做測試reult打印只有16 ... 我希望它打印成功或通過/失敗 如果你可以發佈一個例子,這將是一個很大的幫助。Testng打印結果通過/失敗

public class EdiitAttendancePunchesByDepartment { 

    public EdiitAttendancePunchesByDepartment() { 
    } 

    @BeforeClass 
    public static void setUpClass() { 
    } 

    @AfterClass 
    public static void tearDownClass() { 
    } 

    @BeforeMethod 
    public void setUp() { 
    } 

    @AfterMethod 
    public void tearDown() { 
    } 
    Boolean t = true; 

    @Test(priority = 0,dataProvider = "globalcfg") 
    public void global(String propid, String propvalue) throws IOException { 
     ConfigurationBean cfgbean = new ConfigurationBean(); 

     for (ConfigurationModel cc : cfgbean.getConfigurationList()) { 
      if (cc.getPropertyId().equals(propid)) { 
       cc.setPropertyId(propid); 
       cc.setPropertyValue(propvalue); 
       System.out.println("Propid : " + cc.getPropertyId() + " value : " + cc.getPropertyValue()); 
      } 
     } 

     File output = new File("D:/data/kishore/Edit_punches_output.xls"); 
     FileWriter writes = new FileWriter(output.getAbsoluteFile()); 
     BufferedWriter bw = new BufferedWriter(writes); 
     bw.write("EmpID-Date-Punch_Times-PayDay-Total_IN_Hours-OT-TEST_ID-Leave_Type"); 
     bw.close(); 

     cfgbean.setCreateButtonFlag(Boolean.FALSE); 
     cfgbean.setUpdateButtonFlag(Boolean.TRUE); 
     cfgbean.updateConfiguration(); 
     cfgbean.retrieveConfiguration(); 
     for (ConfigurationModel cc : cfgbean.getConfigurationList()) { 
      if (cc.getPropertyId().equals(propid)) { 
       System.out.println("Propid Out Put : " + cc.getPropertyId() + " value Out Put: " + cc.getPropertyValue()); 
      } 
     } 
     System.out.println("Global Config running>>>>>>>>>>>>>>>"); 
     boolean tr=Reporter.getCurrentTestResult().isSuccess(); 
     System.out.println("Check<><><><><><><><><><><><><><><><><><><><>"+tr); 
     if(tr==true){ 
      System.out.println("Result /////////////////////////////////////"+tr); 
     } 
     System.out.println("Test result>>>>>>>>>>>>>> "+Reporter.getCurrentTestResult().getStatus()); 
    } 

    @Test(priority = 1,dataProvider = "viewpunches") 
    public void testviewpunches(String cmpcode, String orgcode, String Empid, String Empname, String deptname, Integer compgrpid, 
      String date, String Time1, String Time2, String type, String typeid) { 

     EditEmpTimeSheetBean bean = new EditEmpTimeSheetBean(); 
     bean.setCmpCode(cmpcode); 
     bean.setOrgCode(orgcode); 
     try { 
      SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); 
      SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); 
      Date date1 = format.parse(date); 
      Date time1 = format1.parse(Time1); 
      Date time3 = format1.parse(Time2); 
      SimpleDateFormat op = new SimpleDateFormat("dd/MM/yyyy"); 

      bean.setTimeSheetDate(date1); 
      bean.setEmpCompGroupId(compgrpid); 
      bean.setDepartmentName(deptname); 

      bean.setEmployeeCode(Empid); 
      bean.setEmployeeName(Empname); 
      bean.setDialogFlag(Boolean.TRUE); 
      bean.viewTimeSheetDetailByDepartment(); 

      EmployeeDTO dto = new EmployeeDTO(); 
      EmployeeService service = new EmployeeServiceImpl(); 
      dto = service.retrieveEmployee(bean.getCmpCode(), bean.getOrgCode(), bean.getEmployeeCode()); 
      if (dto == null) { 
       File output = new File("D:/data/kishore/Edit_punches_output.xls"); 
       FileWriter write_new = new FileWriter(output, true); 
       BufferedWriter bw_new = new BufferedWriter(write_new); 
       bw_new.write("\n" + bean.getEmployeeCode() + "- NO record found - - - - -" + typeid); 
       bw_new.close(); 
       System.out.println("Invalid Employee Code"); 
      } else { 
       System.out.println("Valid code"); 
      } 


      for (EmpWorkLogModel cc : bean.getEmpWorkLogArray()) { 
       if (cc.getEmployeeCode().equals(Empid)) { 
        cc.onChange(); 
        List<LogTimeModel> kl = new ArrayList<LogTimeModel>(); 
        LogTimeModel m = new LogTimeModel(); 
        LogTimeModel mn = new LogTimeModel(); 

        m.setPunchTimes(time1); 
        if (type.equalsIgnoreCase("insert")) { 
         m.setOpFlag(Constant.OP_FLAG_INSERT); 
        } 
        if (type.equalsIgnoreCase("update")) { 
         m.setOpFlag(Constant.OP_FLAG_UPDATE); 
        } 
        if (type.equalsIgnoreCase("delete")) { 
         m.setOpFlag(Constant.OP_FLAG_DELETE); 
        } 
        mn.setPunchTimes(time3); 
        if (type.equalsIgnoreCase("insert")) { 
         mn.setOpFlag(Constant.OP_FLAG_INSERT); 
        } 
        if (type.equalsIgnoreCase("update")) { 
         mn.setOpFlag(Constant.OP_FLAG_UPDATE); 
        } 
        if (type.equalsIgnoreCase("delete")) { 
         mn.setOpFlag(Constant.OP_FLAG_DELETE); 
        } 
        if (type.equalsIgnoreCase("CHANGE")) { 
        } 
        kl.add(m); 
        kl.add(mn); 
        cc.setPunchList(kl); 
        System.out.println("punch time>>>>>>>>>>>>>>>>>XXXXXXXXX>>>>>>>>>>>>XXXXXXXXXX " + mn.getPunchTimes() + "  " + cc.getPunchTime() + " " + cc.getFromDate()); 

        System.out.println("Emp ID : " + cc.getEmployeeCode() + " \nPunch time : " + cc.getPunchTimes() + " \nPay Day : " + cc.getPayDay() + " \nIN hours: " + cc.getWorkedTime()); 

       } else { 

        System.out.println("\n\nNo Records found for : " + cc.getEmployeeCode()); 
       } 
      }System.out.println("Test result>>>>>>>>>>>>>> "+Reporter.getCurrentTestResult().getStatus()); 
      bean.updateLogTime(); 
      testview(bean.getEmployeeCode(), bean.getEmployeeName(), bean.getShiftId(), date, typeid); 



     } catch (Exception e) { 
      System.out.println(" Error :" + e); 
      e.printStackTrace(); 
     } 

    } 

這是i的輸出接收

sessionFactory1 [email protected] sessionFactory1 SessionStatistics [實體計數=計數0collection = 0] PROPID:com.rgs.payroll。 enableDynamicWeekOff值:PROPID出把 :com.rgs.payroll.enableDynamicWeekOff值Out放:N全局配置 運行>檢查<> <> <> <> <> <> <> <> <> <>假測試結果>>>>>>>>>>>>>> 16

+0

問題似乎是在這片代碼'Reporter.getCurrentTestResult()的getStatus的()'。我沒有看到列出的源代碼,但我會建議看看'getStatus()'返回的是什麼 –

+0

您可以實現監聽器(ITestListener)或IReporter以按照您希望的方式打印結果 –

回答

0

16裝置"STARTED"

這是您可以期望進入測試本身的唯一值。 TestNG只會確定方法結束後的值。

您可以嘗試打印@AfterMethod方法的結果。

1

刪除通從烏爾測試用例失敗的決策代碼,並使用下面的代碼:

@AfterMethod 
public void tearDown(ITestResult result) { 

    if (result.getStatus() == ITestResult.FAILURE) { 
    System.out.println(result.getMethod().getMethodName()+ " is failed"); 
    //do something here. 
    }   
} 
相關問題