简体   繁体   English

如何用Java编写相同场景的正负测试用例?

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

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

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) (如果那是您的要求)

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

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM