Unlike many, I did not play around with the release candidate builds of Visual Studio 2017 much. I knew it was out there and had it installed, but never got around to using it much. With the official release on March 7th, I was excited to see the finished version and being using some of the new features. One that stood out to me, and has been hyped by others online, is the new Live Unit Testing feature.
What Is It?
I was always a huge fan of NCrunch, but most developers I work with do not have a license. With our onboarding program at work we do not regularly have access to it either. As a compromise, we have been using the NUnit Test Adapter extension and the “Run Tests After Build” option to simulate continuous testing. As long as you are regularly building your projects, the tests will run and CodeLens will give you decent visual feedback.
Live Unit Testing takes this the next step to better mimic some of the base functionality I always liked with NCrunch. You get markers next to lines of code (all code, not just test code) to show if their are passing or failing tests associated with the code.
How Do I Get Started?
A couple of notes before getting started. This feature is only available in the Enterprise edition. It does not currently work with .NET Core, which embarrassingly took me a few minutes to discover. Despite it being mentioned in Steve Smith’s article and VS2017 giving me an error saying the same thing. Also, I had to add the NUnit Test Adapter as a reference on the Test project itself. Having it installed as a Visual Studio extension did not work and Live Testing would not start.
To get started you need to go to Test -> Live Unit Testing -> Start. You can pause or start at anytime. There is also an option in Visual Studio to start Live Unit Testing automatically if you prefer.
The tests are being run behind the scenes as you make changes, so is not dependent on you remembering to build your project, or even saving. This is great as the feedback is constant and the human element is minimized. Live Unit Testing is also smart enough to figure out which tests need run as you are modifying the code, instead of constantly running all of your unit tests and degrading performance.
It is a great tool to use when developing. I’m excited to use it myself, but more so as a trainer to get other developers using it and thinking about their tests more often. The visual feedback will help reinforce what we teach with TDD and letting the code base evolve, versus delaying testing to the end.
For more information on Live Unit Testing in Visual Studio 2017, check out these other great articles on the new feature: