In this article, we shall learn how to work with Live Unit Test of VS2017 Enterprise Edition
Introduction
Visual Studio 2017 Enterprise Edition has come up with a new feature call as Live Unit Testing. Microsoft defines it as
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, in real-time. In addition to giving feedback on the impact that your changes had on the existing tests, you also get immediate feedback on whether the new code you added is already covered by one or more existing tests. This will gently remind you to write unit tests as you are making bug fixes or adding features. You will be on your way to the promised land where there is no test debt in your code base!
In this article will give us a quick view as how to work with this new feature.
Prerequisite
We need to install Visual Studio 2017 Enterprise Edition from here.
Straight to the working mode of Live Unit Test
Let us open Visual Studio 2017 IDE ->File->New --> Project.
From the template, under Visual C#, choose Test template and create a new Unit testing project.
The UnitTest1.cs file will appear as under
Write the below code inside the TestMethod1 as under
public void TestMethod1()
{
var expected = "Hello Live Unit Testing";
var actual = "For Enterprise Edition2017";
Assert.AreEqual(expected, actual);
}
Now Click Test -> Live Unit Testing -> Start.
This starts the Live Unit Testing(observe the output window)
This test case will fail since there is a mismatch between expected and actual values.
Now let us modify the TestMethod1 as under
public void TestMethod1()
{
var expected = "Hello Live Unit Testing";
var actual = "Hello Live Unit Testing";
Assert.AreEqual(expected, actual);
}
We can figure out that, we have not hit the Start button yet but the Live Unit Testing has already started.
This time the test case succeeds.
To extend the concept we have added another test method TestMethod2 and modified TestMethod1. The Live Unit Testing continues to run in the background and displays the results in the Output Window as expected
Let's modify both the test method's with the Live Unit Testing behavior being.
Conclusion
Live Unit Testing is a very good add on for the development purpose as it will immediately notify the status and thereby enhance the developer productivity. Hope this will be helpful. Thanks for reading the article. Zipped file attached.