什么是单元测试等?
我注意到 Visual Studio 2010 和 Netbeans 7 中进行测试的功能,并且想知道它们到底做了什么。使用它们会比设计自己的测试更有效吗?
I've noticed the features for making tests in Visual Studio 2010 and Netbeans 7 and was wondering what they do exactly. Would using them be more efficient than designing my own tests?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
单元测试(与集成测试相反)是测试单个单元(通常是一个类)功能的测试(通常实际上是碰巧存在于同一类和文件中的多个测试)。
相比之下,集成测试测试多个不同单元的交互。端到端测试是一种特殊类型的集成测试,用于测试整个软件堆栈,从 UI 到底层的所有内容。
可以进行两种不同类型的测试:“玻璃盒”和“黑盒”。 “黑盒”测试与实现无关;它仅基于函数/类的记录行为编写,并确保任何任意实现都遵循记录的行为。它还可能包括对各种理论实现可能产生的潜在错误的测试,但不考虑实际实现的作用。相比之下,“玻璃盒”测试是一种利用实现知识并确保实现中的每个代码路径都经过测试的测试。一个好的测试是由全面的黑盒测试和玻璃盒测试组成的。
有许多不同的免费库可以轻松创建单元测试。我强烈建议使用 googletest 和 gmock(两者都在 Google 广泛使用)用于测试。
A unit test (as opposed to an integration test) is a test (usually actually multiple tests that happen to exist in the same class and file) that test the functionality of a single unit (typically a class).
An integration test, by contrast, tests the interactions of multiple different units. An end-to-end test is a particular type of integration test that tests an entire software stack, from the UI to everything beneath.
There are two different types of tests that one can conduct: "glass box" and "black box". A "black box" test is implementation-agnostic; it is written based only on the documented behavior of the function/class and ensures that any arbitrary implemenation adheres to the documented behaviors. It may also include tests for potential errors that various theoretical implementations might make, but is done without regard to what the actual implementation does. By contrast, a "glass box" test is one which takes advantage of knowledge of the implementation and ensures that each code path in the implementation has been tested. A good test is one which consists of both comprehensive black box and glass box testing.
There are a number of different freely available libraries that make it easy to create unit tests. I strongly recommend using googletest and gmock (both used extensively at Google) for your testing.
单元测试涉及测试独立于它们通常关联的上下文的各个类或函数。这可以通过消除在弄清楚代码到底为何导致错误时涉及的一些猜测游戏来减少故障排除时间。对于包含大量代码或涉及许多人员的大型企业规模项目,单元测试通常值得花费时间和精力。
Unit tests involve testing individual classes or functions independent of the context they are normally associated with. This can cut down troubleshooting time by eliminating some of the guessing games involved when figuring out why exactly your code is causing errors. Unit tests are usually worth the time and effort involved for larger enterprise scale projects with large amounts of code or many people involved.