unit-testing - 既然我已经将所有单元测试迁移到 MSpec,我还需要 NUnit 吗?

标签 unit-testing tdd nunit bdd mspec

我正在使用 NUnit 进行 TDD。我以行为风格命名我的 NUnit 测试(比如给定、何时、然后)。但是,我现在使用 MSpec 进行所有单元测试。我仍然首先编写测试,使用模拟等......所以,它们仍然是单元测试。但是,我认为不需要 NUnit。

我很紧张要放弃我为学习 NUnit 所做的所有努力。考虑到 BDD 是 TDD 做的对,我是否应该完全放弃 TDD/NUnit?

最佳答案

现在您已经接受了 BDD,您正在遵循“由外向内”的开发方法。

可以在 programmers.stackexchange.com 中找到此开发技术的简洁定义。 .我引用:

"Outside-In (London school, top-down or "mockist TDD" as Martin Fowler would call it): you know about the interactions and collaborators upfront (especially those at top levels) and start there (top level), mocking necessary dependencies. With every finished component, you move to the previously mocked collaborators and start with TDD again there, creating actual implementations (which, even though used, were not needed before thanks to abstractions). Note that outside-in approach goes well with YAGNI principle."



使用 BDD 时,您以自上而下的方式开发并模拟依赖项以满足您的测试。一旦您的 BDD 测试通过,您就可以恢复使用 TDD 来实现您在 BDD 测试期间遇到的依赖项的具体版本(使用“由内而外”的方法)。

因此,您的 TDD 和 BDD 测试都很有值(value),因为它们测试您代码的不同方面,即 BDD 测试确保针对系统中的所有层测试用户的交互,而 TDD 测试详细和详细地涵盖各个组件隔离(通过模拟)。

所以不要放弃你的 NUnit 测试!

为了结束我的回答,你说:

BDD is TDD done right



正如我在上面解释的那样,BDD 和 TDD 之间的主要区别在于它们涵盖的代码范围。 Dan North 有一篇关于此的好文章 here .

关于unit-testing - 既然我已经将所有单元测试迁移到 MSpec,我还需要 NUnit 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19681719/

相关文章:

tdd - 创新的软件工程方法

c# - 我如何在这样的设置中使用 IoC?有没有更好的方法来测试这个?

c# - 使用不同的数据模型进行测试

c# - 在 NUnit 测试中卸载外部非托管 dll

java - Google Guava Predicates.or() 或 Predicates.and() 类型

javascript - Mocha异步执行顺序

ruby - 使用 Ruby 的数据驱动开发框架

unit-testing - 单元测试……应该用在这里吗?

javascript - 如何在 jasmine 中测试 javascript Promise 函数

f# - 为什么我不能在 F# 中使用最新版本的 NUnit 和 FsCheck?