MSTest
MSTest is a software unit testing framework developed by Microsoft, which integrates closely with Visual Studio. MSTest lets you create, manage and run unit tests from within the Visual Studio IDE, as well as externally, from the command line.
MSTest Design
The MSTest framework has a design that is familiar to those who have worked with NUnit in the past.
Test Class
Test classes are declared as such by decorating a class with the [http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testclassattribute(VS.80).aspx TestClass attribute]. The attribute is used to identify classes that contain test methods. Best practices state that test classes should contain only unit test code.
Test Method
Test methods are declared as such by decorating a unit test method with the [http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testmethodattribute(VS.80).aspx TestMethod attribute]. The attribute is used to identify methods that contain unit test code. Best practices state that unit test methods should contain only unit test code.
Assertions
An assertion is a piece of code that is run to test a condition or behavior against an expected result. Assertions in MSTest are executed by calling methods in the [http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert(VS.80).aspx Assert class].
Initialization and Cleanup Methods
Initialization and cleanup methods are used to prepare unit tests before running and cleaning up after unit tests have been executed. Initialization methods are declared as such by decorating an initialization method with the [http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testinitializeattribute(VS.80).aspx TestInitialize attribute], while cleanup methods are declared as such by decorating a cleanup method with the [http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcleanupattribute(VS.80).aspx TestCleanup attribute].
Sample Test
Below is a very basic sample unit test:
[TestClass()]
public class TestClass
{
[TestMethod()]
public void MyTest()
{
Assert.IsTrue(true);
}
}See also
- Software Testing
- Unit Testing
- Test Driven Development
- List of Unit Testing Frameworks
External links
- [http://msdn.microsoft.com/en-us/library/ms379625(VS.80).aspx A Unit Testing Walkthrough with Visual Studio Team Test]
- The evolution of Unit Testing Syntax and Semantics
- Kent Beck's original testing framework paper
- Roy Osherove's book excerpts on Unit Testing: The Art Of Unit Testing
- List of articles on unit testing
- History of unit test frameworks (Andrew Shebanow)
- Why, When, How: Unit Testing white paper (Adam Kolawa)
- Unit Testing Guidelines from GeoSoft
- Test Driven Development (Ward Cunningham's Wiki)