如何在testcase中的方法内打印值?
我需要使用测试用例打印方法内的值。 我的代码是:如何在testcase中的方法内打印值?
public void testgetAllRatingElementsWeekNo() throws Exception {
String METHOD_NAME = "testgetAllRatingElementsWeekNo";
log.entering(CLASS_NAME, METHOD_NAME);
populateForTestMethodValues("1");
populateWeekOfList();
int allRatingElementsWeekNo = weeklyDlvyInstancesDashboardReportForm.getAllRatingElementsWeekNo();
System.out.println("allRatingElementsWeekNo :" + allRatingElementsWeekNo);
assertEquals("testgetAllRatingElementsWeekNo is Not Greater than Zero: ", allRatingElementsWeekNo > 0, allRatingElementsWeekNo);
log.exiting(CLASS_NAME, METHOD_NAME);
}
我需要之前打印我的价值抛出一个异常。
回答:
您可以添加一个try和finally块,最后您可以打印该消息。我不知道这是否可以做得比这更好的方式:
public void testgetAllRatingElementsWeekNo() throws Exception {
try {
String METHOD_NAME = "testgetAllRatingElementsWeekNo";
log.entering(CLASS_NAME, METHOD_NAME);
populateForTestMethodValues("1");
populateWeekOfList();
int allRatingElementsWeekNo = weeklyDlvyInstancesDashboardReportForm.getAllRatingElementsWeekNo();
System.out.println("allRatingElementsWeekNo :" + allRatingElementsWeekNo);
assertEquals("testgetAllRatingElementsWeekNo is Not Greater than Zero: ", allRatingElementsWeekNo > 0, allRatingElementsWeekNo);
} finally {
log.exiting(CLASS_NAME, METHOD_NAME);
}
}
以上是 如何在testcase中的方法内打印值? 的全部内容, 来源链接: utcz.com/qa/257696.html