| Software Testing in Microsoft |
| Written by Edvin Eshagh |
|
In this article, I’ll briefly touch on Microsoft test framework. Like third party unit tests such as NUnit, Microsoft testing framework utilizes reflections to inspect object details at runtime.Microsoft’s testing framework offers the following additions in comparison to third party unit test frameworks: “IDE integration, code generation, new attributes, enhancements to the Assert class, and built-in support for testing nonpublic members”. The last point provides is an important feature when a tester wishes to employ white box testing. To start, you’ll need to include Microsoft.VisualStudio.TestTools.UnitTesting namespace in your code, and then annotate your class with “[TestClass]” attribute. Similarly, your test methods will be annotated with “[TestMethod]”. For example: namespace MyNameSpace { [TestClass] public class MyClass{ [TestMethod] public void MyMethodTest() {…Assert()} }In unit testing, it maybe wise to adhere to three A’s pattern, which is Arrange, Act, Assert. You begin by Arranging your variables and methods, then you Act by invoking your test logic, and then you Assert the result with expected outcome. When you start creating elaborate unit tests you’ll need to do some housekeeping for initialization and cleanup routines. These activities span 1) before/after class unit tests, 2) single time before/after any tests in a class, and 3) single time before/after tests in an assembly. Similar to [TestMethod] attribute, these implementations are identified for initialize/cleanup via corresponding annotation: [TestInitialize], [TestCleanup], [ClassInitialize], [ClassCleanup], [AssemblyInitialize, AssemblyCleanup]. The tests can have “TestContext”, which provides environmental and parameter data. This is especially important if you wish to employ data driven tests. That is, database or a text file will act as an input source for your testing modules. The nice thing about MSTest is that you can use the “Code Generation” in microsoft visual studio IDE by right clicking on a method or a class to build the boilerplate for your tests. With the tests in place, Microsoft shows your code coverage and provides impact analysis based on code changes (how cool is that). “Test Driven Development: By Example” (Kent Beck, Addison-Wesley Professional, 2002) and “Test-Driven Development” (Jim Newkirk and Alexei A. Vorontsov, Microsoft Pres, 2004) are considered required reading by the authors “Professional Application Lifecycle Management with Visual Studio 2010” Several Testing frameworks exists, and you may find the following comparison informative: http://xunit.codeplex.com/wikipage?title=Comparisons Source: Professional Application Lifecycle Management with Visual Studio 2010 |