C# 的 Nunit 和代码覆盖率
我正在使用 C# + .Net 4.0 + VSTS 2010。我想知道 Nunit 是否是该平台(C# + .Net 4.0 + VSTS 2010)最好且易于学习的单元测试工具?如果是,我想学习 Nunit 的基础知识,并且还想找到如何根据 Nunit 结果生成代码覆盖率报告(例如代码覆盖率报告以显示哪个函数已测试,哪个函数未测试,测试了多少行。 )
对于新手来说,有什么推荐的 Nunit 和代码覆盖率教程吗?
I am using C# + .Net 4.0 + VSTS 2010. I am wondering whether Nunit is the best and easy to learn unit test tool for this platform (C# + .Net 4.0 + VSTS 2010)? If yes, I want to learn basics of Nunit, and also want to find how to generate code coverage report based on Nunit result (e.g. code coverage report to show which function is tested, which function is not tested, how many lines are tested.)
Any recommended tutorials for Nunit and code coverage for a newbie?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我将这篇关于 NUnit 初学者的教程发送给了一些与我一起工作的初级人员
http://www.dotnetspider .com/tutorials/NUnit-Tutorials.aspx
另外,在您掌握单元测试之前,我现在还不太担心覆盖范围。单元测试涉及更多内容,例如依赖注入和模拟框架,以确保代码被覆盖并且可测试。
就我个人而言,我首先从事集成和单元测试,然后再进行覆盖范围 - 只是我的 2 美分
希望它对
保罗有帮助
I sent this tutorial on NUnit for beginners to some juniors I work with
http://www.dotnetspider.com/tutorials/NUnit-Tutorials.aspx
also coverage is something I wouldn't quite worry about for now until you get to grips with unit testing. There are more things involved in unit testing like dependency injection and mocking frameworks to make sure that code gets covered and is testable.
personally id work on integration and unit testing first and then move in coverage - just my 2 cents
hope it helps
paul
对于代码覆盖率,您可以使用 ncover,VS 中有一个很好的集成,称为 testdriven.net。
如果您使用的是 VS 2010,您可能还想检查内置测试框架 (MSTest),它也具有内置覆盖率,
希望它有所帮助
for code coverage you can use ncover, there is a nice integration into VS that is called testdriven.net.
If you are on VS 2010 you might also want to check the builtin test framework (MSTest) that also has coverage builtin
hope it helps
C# 中覆盖率的单元测试
我知道自 OP 以来事情已经发生了一些变化,但是 coverlet 是免费,用于 用于 C# 单元测试代码覆盖率的 ms 教程,并支持 nunit、xunit 和 mstest。
基本说明是将包添加到 C# 测试项目中:
dotnet add package coverlet.collector
,然后使用标志运行测试:
dotnet test --collect:"XPlat Code Coverage"
code>也许是题外话 VSCode 覆盖率显示插件说明
VSCode coverage-gutters< /a> 可用于消耗输出。它将源代码着色为显示覆盖率结果的一种方式。
看起来 coverlet 生成了一个名为“coverage.cobertura.xml”的文件,因此您只需将其添加到覆盖文件列表中即可查找。在 settings.json 中添加以下设置:
"coverage-gutters.coverageFileNames": ["coverage.cobertura.xml"],
并运行“Coverage Gutters: Watch”命令。
Unit Tests with Coverage in C#
I know that things have changed somewhat since the OP, but coverlet is free, is used in the ms tutorial for C# unit test code coverage, and supports nunit, xunit, and mstest.
Basic instructions are to add the package to your C# test project:
dotnet add package coverlet.collector
and then run tests with a flag:
dotnet test --collect:"XPlat Code Coverage"
Maybe Off-topic VSCode Coverage Display Plugin Instructions
VSCode coverage-gutters can be used to consume the output. It colorizes your source code as a way to show coverage results.
It looks like coverlet generates a file called "coverage.cobertura.xml", so you just need to add it to the list of coverage files to look for. In settings.json add the following setting:
"coverage-gutters.coverageFileNames": ["coverage.cobertura.xml"],
And run the "Coverage Gutters: Watch" command.
制作 ReSharper (JetBrains) 的公司现在拥有自己的覆盖工具,名为 dotCover。截至目前,我认为 dotcover 和 Resharper 组合起来比 ncover 便宜。
The company that makes ReSharper (JetBrains) now has their own coverage tool called dotCover. As of now, I think dotcover and Resharper combined are less expensive than ncover.