gpt4 book ai didi

c# - 在同一个程序集中混合单元测试和集成测试

转载 作者:太空狗 更新时间:2023-10-30 01:36:33 24 4
gpt4 key购买 nike

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

集成测试目前是在没有特殊框架(如 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# - 在同一个程序集中混合单元测试和集成测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21785098/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com