How to run an NUnit test in VisualStudio with OpenCover code coverage?

泪湿孤枕 提交于 2020-01-03 11:34:12

问题


I am new to NUnit testing. I was able to write test cases for my functions, now what I want is to know the code coverage for my test cases. For that I use OpenCover. But I don't know how to install and get OpenCover to work with Visual Studio 2015, can anyone guide me to install OpenCover for Visual Studio and provide help to see the code coverage in Visual Studio?


回答1:


The best solution I found for code coverage in Visual Studio is as follows:

  1. Open Visual Studio 2017
  2. Go to Tools->Extensions and Updates
  3. Go to "Online", in the search (top right of the window) type "AxoCover"
  4. Click install, follow the instructions (i.e. close Visual Studio to start the install)
  5. Reopen Visual Studio
  6. Build your project
  7. Go to Tools->AxoCover
  8. Under the "Tests" tab right click your top directory and go "Cover tests"
  9. Click on the "Report" tab




回答2:


You need some VS extension to include the coverage results in VS. One example: https://visualstudiogallery.msdn.microsoft.com/6950a046-8919-4935-8542-c6f37956f688/view/

  • you need OpenCover installed/present in solution
  • you need NUnitConsole installed/present in solution
  • it does not support VS2017
  • NUnit3 supported only when you do a custom build from git (not in latest release)

I have nothing to do with this extension, it is just working for me. Use at your own risk :)

If you mean it and you can spent some $ go for http://www.ncrunch.net/



来源:https://stackoverflow.com/questions/43089457/how-to-run-an-nunit-test-in-visualstudio-with-opencover-code-coverage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!