This post is about Live Unit Testing in Visual Studio 2017. With VS2017, Microsoft released Live Unit Testing. Live Unit Testing automatically runs the impacted unit tests in the background as you edit code, and visualizes the results and code coverage, live in the editor.
This feature is only available Visual Studio 2017 Enterprise edition. Live Unit Testing feature works with XUnit, NUnit and MS Test Frameworks. In this I am using MS Test Framework.
First you need to install Live Unit Testing component. You can install it via Visual Studio Installer.
Once installation completed, you can enable the Live Unit Testing from Test Menu.
For this post I have created a simple Calculator class, which helps to do mathematical operations. Here is the implementation.
And here is the Unit Tests for the methods.
You can start Live unit testing from Test menu >Live Unit Testing >Start.
Once Live Unit Testing started, you can the various status in the Visual Studio editor.
Here is the various status of unit tests.
- Red Icons - If a line of executable code is covered by at least one failing test, Live Unit Testing will decorate it with a red cross mark.
- Green Icons - If a line of executable code is covered by only passing tests, Live Unit Testing will decorate it with a green tick mark.
- If a line of executable code is not covered by any test, Live Unit Testing will decorate it with a blue dash.
Clicking on the icon will display the affected tests.
Clicking on the red icons will display the failed test details. Also clicking on the test, which helps you to navigate to the specific test.
You can Pause / Stop or Restart live unit testing.
Happy Programming :)