How to write the positive and Negative test cases of same scenario in java?

Adalarasan_Serangulam picture Adalarasan_Serangulam · Jan 3, 2013 · Viewed 12.3k times · Source

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

Answer

assylias picture assylias · Jan 3, 2013

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)