Live Unit Testing In Visual Studio 2017

Let’s have a look at one of the coolest features of Visual
studio 2017. If you see the snapshot given below, there are many new icons here.

These icons are part of a cool new feature called Live Unit Testing in Visual Studio 2017 Enterprise.

Live Unit Testing continuously runs and displays unit test
results and code coverage inside the editor itself. It automatically finds and runs the impacted tests for every line of code. In the diagram shown above, the red cross indicates a failed test case, the green tick indicates the passed test case and the blue minus symbol indicates the code that has no test coverage at all.

Let’s start by looking at failing test cases. You can quickly
navigate to failing test cases by clicking on tooltip, as shown below.

And below is my test case.

At this point, I’m not really sure why this is failing. Thus,
I’ll go ahead and debug this test.

We can see here that the particular code, shown above has thrown a null
reference exception.

Please note that a new exception handler has been introduced
in VS 2017. Now, one can see complete exception details here.

Now, as I got to know the cause of failure, I quickly went
and initialized my field in my constructor, as shown below.

As soon as I updated my code, editor is showing test case as
passed. Hope you enjoyed learning this new feature.