Skip to main content

Live Unit Testing in Visual Studio 2017

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

























These icons are part of cool new feature called Live unit testing in Visual Studio 2017 Enterprise.

Live Unit Testing continuously runs and displays unit test result and code coverage inside editor itself. It automatically finds and runs impacted tests for every line of code. In above diagram, Red cross indicates failed test case, Green tick indicates passed test case and Blue minus indicates the code that have no test coverage at all.

Let’s start by looking at failing test case. You can quickly navigate to failing test case 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. So, I’ll go ahead and debug this test
We can see here that above particular code 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 itself.








Now as I get to know the cause of failure, I quickly went and initialized my field in my constructor as:







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

Comments