Introduction to Unit Testing Framework of VS 2008: Part II
This article gives an introduction to creation and configuration of Ordered Tests of VS 2008 Testing Framework.
In this article, I am going to explain some more features of Testing Framework of VS 2008. I am going to extend the same sample code used in previous article. Here, I am going to discuss about ordering execution of test cases and configuring it.
In previous article, I created a simple test project with two test methods in it. Now, we will order the execution of those test cases. In NUnit, we can’t define the sequence of test cases execution. But this framework will allow us to define the flow of test cases execution.
Uses of Ordered Test Cases:
- Allows us to run n test cases in a specific order.
- Allows us to group test cases and get result as a whole.
- Allows us to have nested ordered test cases.
First, open the sample project code attached here. In that, we can see two test methods in class Class1Test. I am adding one more test method to this for better understanding.
First add this method to Class1.cs:
public int MultiplyNumbers(int a1, int b1)
return a1 * b1;
To create test method to it, just right click on the method and select Create Unit Tests, by default MultiplyNumbers() will be selected.Since,we have not created test case for that method only. Change the default values & remove Assert.Inconclusive statement present in the newly added test method.
We are ready with three test methods. Now, we can define sequence of execution of this test cases.
Right click on Test project in Solution Explorer and select Add --> Ordered Test. It will list all test cases as shown below:
Just move following test methods to selected tests:
Now, we are ready with ordered tests. We will run it, by going to Test --> Windows --> Test List Editor and select OrderedTest1 and click on Run Checked Tests.
We can see test result as Passed. Go to SquareTest method and change expected as 26 and run the test case OrderedTest1 in Test List Editor.Now,the result will be failed.
Since, we defined the order of test cases execution. First, it will execute AddNumbersTest (result will be passed), then SquareTest (result will be Failed), so it won't execute MultiplyNumbersTest at all. We can see the complete details of ordered test by double clicking OrderedTest1 in Test Results window as shown below:
If we want to execute all test cases present in Ordered Test irrespective of test result. Just goto OrderedTest1.orderedtest and check Continue After Failure checkbox. So that, it will execute all test cases.
In coming article, I will dicuss other important features of this Framework.I am attaching code for reference.I hope this code will be useful for all.