Prepare to "Run IntelliTest" with Visual Studio 2015

Posted by David Jung - July 17, 2015

header-picture

Anyone who is doing agile development will preach about how you need developer unit tests in the code base in order for automated builds to be effective. If you don't, all you really know is that your code compiles on a another machine without any handholding. In order for automated builds to be beneficial, you need to test to see if your compiled code actually works to some degree.

As much as development teams want to have unit tests throughout their code, they often don't know where to start or feel they don't have time to write them. There are a lot of techniques to help you figure out where to start, but starting with Visual Studio 2015, Microsoft has just given you a tool to help, not just another technique.

This tool is called IntelliTest (formally known as Smart Unit Tests) and when run, it will go through the code section you select, auto-create unit tests for you, and execute them against the different conditional paths it discovered.

Let's assume been tasked to take a look at some methods that have been causing some intermediate problems. The project does not have unit tests, so you step through the code, generate a CodeMap to give you a clearer execution path, look at values in the Watch window, and so on but nothing seems to catch your eye as to what could be the problem.

In previous versions of Visual Studio, there was a tool called "Create Unit Tests" which only created unit test stubs. [Note: This feature has been brought back.] This was a good start but flawed because you would still have to write logic for what you were trying to test. With IntelliTest, this does more than just create unit test stubs, but also generates the unit test to test your code.

To use IntelliTest, right-click anywhere within the method you want to unit test and select Run IntelliTest.

Run IntelliTest

Visual Studio will analyze the code and the execution paths it takes, generate a number of unit tests that will test the different paths, and execute the unit tests. The results of the tests show in the IntelliTest Exploration Results pane.

IntelliTrace Exploration Results pane

In this example, IntelliTest created seven unit tests, five that passed and two that didn't. One of the tests that failed was because Null values were passed into the method. The other test that failed was because an invalid value was passed into the Employee object. You can see that by selecting the test that failed and show the Details section. It's very likely that these two different unit tests might have been the cause of the intermittent problems.

IntelliTest Exploratation Result Pane - Details

The unit tests that are created by IntelliTest are not saved within the project so these can't be used with an automated build. If you want to keep any or all of the unit tests IntelliTest generates so you can add them to your automated build, simply select the unit tests you want in the IntelliTest Exploration Result pane and press the Save button.

Save the IntelliTest Unit Tests

This will create a new Test project in your solution and the generated unit tests to the project. This project can be used to store any addition unit tests you decide to add to project.

Using the new IntelliTest feature in Visual Studio 2015, you have no excuse not to have some level of unit test code coverage in any of your projects.

In my next post, I will discuss unit testing with Visual Studio 2015’s IntelliTest.

Excelsior!

IntelliTest,InCycle,Learning,Microsoft,TFS

 

Topics: Blog


Recent Posts

InCycle Named Azure Data Explorer (ADX) Partner

read more

OpsHub & InCycle Help Top Medical Device Company Accelerate Innovation

read more

InCycle Continues to Lead, Recognized by Microsoft for Industry Innovation. Earns Impact Award.

read more