VSTS/IDE Productivity features - look at the unit testing
Visual Studio 2005 comes with an armada of productivity features. This is an extract from the IDE/Debugger productivity demonstration I created for the developer readiness program, exploring and illustrating some of the “many” features all developers should be aware of.
Part 1: a look at the unit testing features.

The creation of unit test classes has become trivial, i.e.
Create Test Class
-
Open the demo DebugDemoClass file in the IDE editor.
-
Right click on the source and select “Create Unit Tests”.

-
Select the appropriate classes for which a unit test class needs to be created.
-
For this lab, select Demo as shown:

-
Specify a meaningful name for the unit test project.

-
Click Create.
-
Review the AuthoringTests.txt file, which contains more information on unit tests.
It is this easy - right click - answer a few simple questions, normally staying with defaults and voila, we have the plumbing code complete.
Complete Test Code
The only real work is to update the unit test plumbing code, implementing some meaningful data and validation. Again the default plumbing is adequate for most unit testing and for those who believe that the KISS principle is the future.
-
Edit the unit test source file.
-
Change valueOne to two (2), valueTwo to four (4) and expected to eight (8) in method MultiplicationPrivateTest(), and remove the last statement which is an inconclusive assertion. In other words the methods expects that the result for 4*2=8.

-
Change valueOne to three (3), valueTwo to two (2) and expected to seven (7) in method MultiplicationPublicTest(), and remove the last statement which is an inconclusive assertion. In other words the methods expects that the result for 3*2=7, which is intentionally incorrect.

-
The third unit test method, MultiplicationStepThroughTest() in the test project is left “as is”.
-
Open the Test Manager, by selecting Test --> Test Windows --> Test Manager
-
Optionally create a TestList by right clicking on Lists of Tests and dragging the relevant tests into the test list.

Execute Unit Tests
-
Select the tests you wish to execute, in our case the three Multiplication*Test() methods, right click and select run checked tests.

-
You will notice that test after test will change from Pending --> In Progress and then to Passed, Failed or Inconclusive.

-
MultipicationPrivateTest shows “passed”, as the function returns the expected result.
-
MultipicationPublicTest shows “failed”, as the function returns the unexpected result, namely 2*3=6, not 2*3=7 as expected.
-
MultipicationStepThroughAttributeTest shows “inconclusive”, because we did not update the test method and the last statement of the method is therefore still the inconclusive assertion, which reminds us of missing logic.

Reports
An amazing package of functionality is hidden with the reporting of the unit tests. Each test is logged and each comes with substantial evidence, as well as the option to re-execute prior unit tests.
-
Review the test result report.

-
Note that when you execute the test more than once, you can select the relevant test from the test drop down and re-run or debug the original tests.

Next time we will have a glimpse at code analysis and code coverage - two powerful companions. ![Big Smile [:D]](/emoticons/emotion-2.gif)