在这里,我试图打印测试用例的结果...... 但无论我做什么,测试reult打印只有16 ... 我希望它打印为成功或通过/失败 如果你能发表一个例子,那将是一个很大的帮助。
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();
}
}
这是我收到的输出
sessionFactory1 org.hibernate.internal.SessionFactoryImpl@196a6ac sessionFactory1 SessionStatistics [entity count = 0collection count = 0] 支持:com.rgs.payroll.enableDynamicWeekOff值:N Propid Out Put :com.rgs.payroll.enableDynamicWeekOff value Out Put:N Global Config 运行&GT;检查&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt; false测试结果&gt;&gt;&gt;&gt; &GT;&GT;&GT;&GT;&GT;&GT;&GT;&GT;&GT;&GT; 16
答案 0 :(得分:1)
从您的测试用例中删除传递失败决策代码并使用以下代码:
@AfterMethod
public void tearDown(ITestResult result) {
if (result.getStatus() == ITestResult.FAILURE) {
System.out.println(result.getMethod().getMethodName()+ " is failed");
//do something here.
}
}
答案 1 :(得分:0)