#VS2015 – IntelliTests a cool tool to test legacy code


If you work with legacy apps, you probably know the hard work needed to create a test Environment this this type of apps. In the most simple scenario, you start writing some code and you need some tests to validate you don’t get into any ugly errors. The main issue, is that you are not allowed to make changes in this apps, so you must cry a couple of days and then, men up and go back to work. (It also applies to crappy code, not only to legacy apps)

So, back in 2010 Microsoft Research present us PEX , nowadays this auto-test feature is part of Visual Studio 2015 and is named “IntelliTests”. This tool perform an automatic code analysis and then generates tests based on this analysis.

Let´s start with a simple based on crappy code, in example the leap motion USB missile launcher app I use in my demos.

There is a complex operation which converts the movement of the hand detected by the leap into a simple constant, so let’s open the context menu ans select “Create IntelliTest

If we don’t have any test Project in our Solution, IntelliTest will suggest us the creation of a new one.

When we have the test Project we realize that the test class is almost empty. IntelliTest is smart enough to create this tests and also later generate the simple data to run this tests. To run a test, let’s open the context menu and select “Run IntelliTest”. Now we can see the total amount of runs and different tests auto generated for the operation.

For this sample, IntelliTest generates 39 different tests with all the needed parameter combinations for GetDirection(). Now is important to remember:

If we change the code of the operation and we run again the option “Run IntelliTest” the tests data set will be generated again based on the new code of the operation.

If our main objective is to have some regression tests, we must SAVE the current set of data sets. Based on the generated tests we can save all the tests, or a subset of tests.

When we save, IntelliTest will generate a new class which can be used for the regression tests. We can also add our own asumptions or assertions which is something very cool to extend the tests. IntelliTest will also provide us some helpers like the creation of a Factory, and other scenarios to make them very powerful.


– El Bruno, Pex for Fun http://geeks.ms/blogs/elbruno/archive/2010/08/20/vs2010-pex-for-fun-ideal-para-ver-quien-paga-las-cervezas.aspx

– MSDN IntelliTest, https://msdn.microsoft.com/library/dn823749(v=vs.140).aspx

Saludos @ Barcelona

/El Bruno

One thought on “#VS2015 – IntelliTests a cool tool to test legacy code

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.