ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

c# – 在同一个组件中混合单元测试和集成测试

2019-06-29 04:54:00  阅读:375  来源: 互联网

标签:c unit-testing asp-net nunit integration-testing


我的队友现在已经理解了(!?)集成测试和单元测试之间的区别.现在,在我们的项目中,为每个组件建立了一个测试组件.

目前,集成测试没有像SpecFlow或Cucumber这样的特殊框架.它们是普通(和长)NUnit测试方法,其中来自不同组件的几个类一起测试.

现在的计划是使用“单元测试”和“集成测试”按属性(C#)对测试进行分类,以便NUnit可以在必要时过滤相应的测试.

是否适合将集成测试和单元测试混合在同一个组件中,还是应该总是在不同的组件中进行分离?

解决方法:

从技术上讲,这可能有用,但你为什么要这样做呢?

单元测试是测试一个“单元”,它可能是一个函数或测试组件所属的组件内的任何其他一小段代码(每个组件的一个测试组件),一个集成测试是关于测试一些逻辑通常在多个程序集中实现,因此为集成测试提供额外的程序集并将它们与单元测试分开,实际上是我眼中更好的配置.

从一些相关的article中读取这个:

Integration Testing While unit tests verify the functionality of a
piece of code in isolation, integration tests verify the functionality
of a piece of code against a target system or platform. Just like unit
tests, integration tests are automated procedures that run within a
testing framework. Although comprehensive unit testing verifies that
your code behaves as expected in isolation, you still need to ensure
that your code behaves as expected in its target environment, and that
the external systems on which your code depends behave as anticipated.
That is where integration testing comes in. Unlike a unit test, an
integration test executes all code in the call path for each method
under test—regardless of whether that code is within the class you are
testing or is part of an external API. Because of this, it takes much
longer to set up the test conditions for an integration test. For
example, you may need to create users and groups or add lists and list
items. Integration tests also take considerably longer to run.
However, unlike unit tests, integration tests do not rely on
assumptions about the behavior of external systems and services. As a
result, integration tests may detect bugs that are missed by unit
tests. Developers often use integration tests to verify that external
dependencies, such as Web services, behave as expected, or to test
code with a heavy reliance on external dependencies that cannot be
factored out. Testers often also develop and use integration tests for
more diverse scenarios, such as security testing and stress testing.
In many cases, organizations do not distinguish between integration
and unit testing, because both types of tests are typically driven by
unit testing frameworks such as nUnit, xUnit, and Visual Studio Unit
Test. Typically, organizations that use agile development practices
make this distinction, because the two types of tests have different
purposes within the agile process.

标签:c,unit-testing,asp-net,nunit,integration-testing
来源: https://codeday.me/bug/20190629/1323052.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有