java java中如何编写相同场景的正负测试用例?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14134221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to write the positive and Negative test cases of same scenario in java?
提问by Adalarasan_Serangulam
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);
}
回答by assylias
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)
(如果那是你要问的)
回答by Bohemian
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());
回答by rai.skumar
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.
所以只需有两种测试方法(一种用于阳性,另一种用于阴性)并分别调用阳性和阴性数据。