给定 NUnit 的 When-Then 示例
有人可以向我指出一些使用 NUnit 进行 Give-When-Then 风格测试的资源吗?
Can anybody point me to some resources for Give-When-Then style of testing with NUnit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Give When Then 风格与单元测试的 Arrange Act Assert 风格密切相关。
这是一个示例:
这种测试风格的优点是您不需要查看底层代码即可理解行为的意图。
有关更多信息,请访问以下网站:
http://www.arrangeactassert.com/
罗伊·奥谢罗夫的博客
http://www.artofunittesting.com/
The Given When Then style correlates closely to the Arrange Act Assert style for unit testing.
Here's an example:
The great thing about this testing style is you don't need to see the underlying code to understand the intent of the behavior.
For more info here are some sites:
http://www.arrangeactassert.com/
Roy Osherove's Blog
http://www.artofunittesting.com/
我知道这是一个老问题,但如果您还没有这样做,您应该查看 SpecFlow。它允许您在功能文件中以明文形式编写规范。该工具将根据功能文件自动生成 NUnit 测试。
I know this is an old question, but if you haven't already, you should check out SpecFlow. It allows you to write the spec in clear text in a feature file. The tool will auto-generate NUnit tests based on the feature file.
如果您下载并添加对 StoryQ 的引用,则可以使用不错的 BDD 样式(通过单击查看示例)链接),同时照常使用 NUnit(以及 TestDriven.Net、R# 的运行程序,或者您拥有的其他工具)。
If you download, and add a reference to, StoryQ, you can use a nice BDD style (see samples by clicking the link) and at the same time use NUnit as usual (and TestDriven.Net, R#'s runner, or what have you).
您还可以查看一个小图书馆
https://www.nuget.org/packages/Heleonix.Testing.NUnit/< /a>
该库提供了在 GWT 中编写测试和AAA 样式采用 JavaScript 的 Jasmine 或 Jest 方式。请参阅自述文件:
https://github.com/Heleonix/Heleonix.Testing/blob/ master/README.md
You might also check a small library
https://www.nuget.org/packages/Heleonix.Testing.NUnit/
Instead of writing comments like
//Arrange, //Act, //Assert
or naming unreadable methods likeGiven_UserIsLoggedIn_When_SomeButtonIsPressed_Then_BlaBla
in you tests, the library provides ability to write tests in GWT and AAA styles in manner of JavaScript's Jasmine orJest. See Readme:https://github.com/Heleonix/Heleonix.Testing/blob/master/README.md