简体   繁体   中英

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

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?

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 (ie 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

AxoCover

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM