Write Unit Test Automatically using IntelliTest in Visual Studio 2015

Write Unit Test Automatically using IntelliTest in Visual Studio 2015

Over the past few posts we have discussed about many topics on Unit Testing in Visual Studio. We have learned, How to write your very first Unit Test , Exploring and Managing Unit Tests and we have seen how the code coverage is one the important aspect to identify the uncovered portion of code. Keeping all these learning on mind, lets learn another aspect of writing Smart Unit Test, using “IntelliTest” in Visual Studio 2015.  IntelliTest helps us to create Unit Test automatically that give maximum of code coverage.

The overall process is very simple looks

IntelliTest in Visual Studio 201

Let’s have a look into how this works. Consider we have following method in a class which adds two positive number. ( We are using same example for all the unit test scenarios to understand it better and keep it simple) .

image

Now, Right Click on the Method, and Select “Run IntelliTest” from the context menu.

image

 

Once you select “Run IntelliTest” , Visual Studio performs certain steps to analyze and generate unit test for us.  You can view these steps from Output Window –> IntelliTest

image

As soon as the processing is done, Visual Studio will launch an another new windows called “IntelliTest Exploration Results”, that generates set of all possible unit tests based on the method parameters and which can cover the maximum of code path of the given code block. These generated test covers all possible combination of parameter values; including boundary condition. As you can see in the below windows, the generated methods with it’s targets and the number of parameter (a, b) and the value that has been used for test parameter.

 

image

If you select any of these targeted method from the IntelliTest windows, you would be able to see the Details of Generated Unit Test by the Pex.  This shows how internally a generated unit test getting called and cover the certain percentage of the code.

image

Select all the Unit Tests and Click in the Save Icon in the “IntellTest Exploration” Windows.

image \

This will add a new Unit Test Project  in the solution with all required assembly added. At this point of time you should be able to build the overall solution.

image

Now you can take help of Test Explorer to review, run and manage all the Unit Tests generated  through the IntelliTest.

Must Read : Exploring and Managing Unit Tests Using Test Explorer in Visual Studio

image

You can also take help of codelens to see the reference Tests methods, along with parameter used for test.

Must Read : Check the Unit Test Status Easily and Effectively – Test Status Indicator in Visual Studio

image

 

The last and final things is Code Coverage.  Read the below highlighted post to understand the basic of code coverage. Similarly, Code coverage for test methods generated through the IntelliTest can also be shown using the Code Coverage Windows.

Must Read :

Understanding Code Coverage – How to determine which portion of code is being tested in Visual Studio ?

How to customize color settings for Code Coverage Result in Visual Studio ?

image

image

You can refer and read this post for more internal details of this feature.

Hope this helps !

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

9 Comments to “Write Unit Test Automatically using IntelliTest in Visual Studio 2015”

  1. The ability to create automatic unit tests is nice, but not very useful for test driven development. Do you feel that this is a way to increase coverage after having written tests for a test driven project?

    Also, would you like help creating a better captcha module. I like what you’re trying, but if someone really wanted to spam you, it would not be very difficult.

Comments are closed.