I want to write the both test cases whether positive scenario and negative scenario.

My sample code is,

    /**
     * 
     */
    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);
    }
有帮助吗?

解决方案

How about this?

To assert it works:

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

To assert the negative case:

// use input data you don't expect results for
assertTrue("testgetASNAccuracyRatingElement is not empty", 
    asnAccuracyInstanceTypeList.isEmpty());

其他提示

This line

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

is strictly equivalent to:

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

(if that was what you were asking)

Input/Test data decides if the test case is for positive or negative case.

So just have two test methods (one for positive and another for negative) and call with positive and negative data respectively.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top