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 test开发者_如何学Pythoned.)
Any recommended tutorials for Nunit and code coverage for a newbie?
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
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
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.
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.
精彩评论