单元测试中什么是正向测试和负向测试
我对 TDD 还很陌生。我看到一些文档提到了阳性测试、阴性测试、边界测试等。有人能告诉我阳性测试和阴性测试之间的区别吗?有没有关于不同类型测试的参考资料? (我不是在找书)
I'm pretty new to TDD. I see some docs says about positive test, negative test, boundary test etc. Can any one tell me the difference between a positive test and negative test? Is there any reference out there that says about the different types of tests? (I'm not looking for books)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
积极测试 - 通过提供有效的信息来测试系统
数据。
负面测试 - 通过提供无效的内容来测试系统
数据。
例如,一个应用程序包含一个文本框,并且根据
文本框应仅接受用户的要求
Strings.By 仅提供 String 作为输入数据
文本框和检查其是否正常工作
意味着它是阳性测试。
如果给出除字符串以外的输入意味着它是负数
测试..
负测试提高了应用程序的测试覆盖率。结合使用否定和肯定测试方法,您可以使用任何可能的输入数据(有效和无效)来测试您的应用程序,并可以帮助您使您的应用程序更加稳定和可靠。
请参阅此词汇表了解不同类型的测试
Positive Testing - testing the system by providing valid
data.
Negative Testing - testing the system by providing invalid
data.
For Example, an application contains a textbox and as per the
user's Requirements the textbox should accept only
Strings.By providing only String as input data to the
textbox & to check whether its working properly or not
means it is Positive Testing.
If giving the input other than String means it is negative
Testing..
Negative testing improves the testing coverage of your application. Using the negative and positive testing approaches together allows you to test your applications with any possible input data (both valid and invalid) and can help you make your application more stable and reliable.
Refer this Glossary for different type of tests
一些快速示例将帮助您更清楚地理解差异。
示例
候选函数:
正测试用例-作为该函数需要一个文件路径,正测试用例将包含所有可能的有效文件路径:
负测试用例-任何可以发送到函数且无效的内容都将处于负测试用例中:
单元测试还可以作为函数的实时文档。因此,负面测试用例应该仅包含预期的异常条件,而不是向函数抛出所有可能的参数。
因此,不需要测试这个 -
Some quick examples will help you to understand the difference more clearly.
Example
Candidate Function:
Positive Test Cases- As this function expects a file path, positive-test-case will comprise with all possible valid file paths:
Negative Test Cases- Any thing that can be sent to the function and is not valid, will be in negative-test-case:
Unit-test also works as a live documentation to your function. So, instead of throwing every possible argument to the function, negative test case should comprise only with expected exceptional conditions.
Hence, don't need to test this-
就单元测试而言(这是 TDD 的重点),概念可以简单地描述如下:
In terms of unit testing, (which is the focus of TDD) the concept can be described simply as follows:
负面测试检查系统是否没有做它不应该做的事情。
示例:如果只有经理可以批准购买新笔记本电脑的请求,则负面测试表明“常规”用户无法批准该请求。
Negative testing checks that the system does not do what it shouldn't.
Example: If only a manager can approve a request for a new laptop, negative testing shows that a "regular" user cannot approve that request.