0

我想编写两个测试用例,无论是正面场景还是负面场景。

我的示例代码是,

    /**
     * 
     */
    public void testgetAsnAccuracyInstanceType() throws Exception
    {
        String METHOD_NAME = "testgetAsnAccuracyInstanceType";
        log.entering(CLASS_NAME, METHOD_NAME);

         //Rating Element "1" ASN Accuracy
         populateForTestMethodValues("1");
         populateWeekOfList();
         List<WeeklyDeliveryInstanceTypeQO> asnAccuracyInstanceTypeList = weeklyDlvyInstancesDashboardReportForm.getAsnAccuracyInstanceType();
         assertTrue("testgetASNAccuracyRatingElement is Not Empty: ", asnAccuracyInstanceTypeList.size() > 0);
         log.exiting(CLASS_NAME, METHOD_NAME);
    }
4

3 回答 3

1

这条线

assertTrue("testgetASNAccuracyRatingElement is Not Empty: ", 
           asnAccuracyInstanceTypeList.size() > 0);

严格等价于:

assertFalse("testgetASNAccuracyRatingElement is Not Empty: ", 
           asnAccuracyInstanceTypeList.isEmpty());

(如果那是你要问的)

于 2013-01-03T06:58:50.143 回答
1

这个怎么样?

要断言它有效:

// use input data you expect results for
assertFalse("testgetASNAccuracyRatingElement is empty", 
    asnAccuracyInstanceTypeList.isEmpty());

断言否定情况:

// use input data you don't expect results for
assertTrue("testgetASNAccuracyRatingElement is not empty", 
    asnAccuracyInstanceTypeList.isEmpty());
于 2013-01-03T06:59:16.840 回答
0

输入/测试数据决定了测试用例是用于肯定用例还是用于否定用例。

所以只需有两种测试方法(一种用于阳性,另一种用于阴性)并分别使用阳性和阴性数据进行调用。

于 2013-01-03T06:58:34.043 回答