Visual Studio 2017 Enterprise provides a feature called Live Unit Testing that enables developers to see live how changing C# and VB.NET code affects its corresponding unit tests. Among its features, it includes showing coverage information in the editor as you type, integration with the Test Explorer, including/excluding targeted test methods or projects for large solutions, quick navigation to failed tests. It works with MSTest, xUnit.net and NUnit, but only for .NET Framework, as support for .NET Standard has not been added yet.
Detailed information about this productivity tool is available in this blog post: Live Unit Testing in Visual Studio 2017 Enterprise. In this article, I will show how this feature help you when you do test driven development. For this purpose, I will create a class called Point3D that is supposed to model a point in 3-dimentional space, as part of a .NET Framework class library called ALibraryHasNoName. A separate unit testing project called ALibraryHasNoName.Test contains an unit testing class Point3DTest. Initially, these are empty.
I don’t like the default names v1, v2, v3 and the fact that these values are represented by fields. I want to use properties called X, Y and Z. Therefore I am refactorying the generated code as shown below:
Next thing I want to do is add a static property/field to represent the origin of the 3D space, i.e. the point at (0,0,0). For this I am writing a new test method with the content shown below. Visual Studio suggests several ways to generate the missing symbol: as a property, field or read-only field, which I find the closest to what I want so I am going with this.
The last thing I want to do for this demo is adding a method to do a translation of the point in the 3d space. I want to call this method Offset. Therefore, I start with a new test method, called TestOffset where I create a point and invoke the new method. Visual Studio suggest to generate the missing method and I will go with the suggested code.
Although this post only covers some of the capabilities of live unit testing I hope it shows how helpful it can be in writing unit tests in general and with TDD in particular. For details about the features check the official documentation.Hits for this post: 1235 .