Question

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);
    }
Was it helpful?

Solution

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());

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top