Visual Studio Unit Testing Framework
Encyclopedia
The Visual Studio Unit Testing Framework describes Microsoft
Microsoft
Microsoft Corporation is an American public multinational corporation headquartered in Redmond, Washington, USA that develops, manufactures, licenses, and supports a wide range of products and services predominantly related to computing through its various product divisions...

's suite of unit testing tools as integrated into some versions of Visual Studio 2005 and later. The unit testing framework is defined in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll. Unit tests created with the unit testing framework can be executed in Visual Studio or, using MSTest
MSTest
MSTest is a command line utility from Microsoft that executes unit tests created in Visual Studio 2005, Visual Studio 2008 or Visual Studio 2010....

.exe, from a command line.

Test class

Test classes are declared as such by decorating a class with the 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 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
Assertion (computing)
In computer programming, an assertion is a predicate placed in a program to indicate that the developer thinks that the predicate is always true at that place.For example, the following code contains two assertions:...

 is a piece of code that is run to test a condition or behavior against an expected result. Assertions in Visual Studio unit testing are executed by calling methods in the 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 TestInitialize attribute, while cleanup methods are declared as such by decorating a cleanup method with the TestCleanup attribute.

Sample Test

Below is a very basic sample unit test:

using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class TestClass
{
[TestMethod]
public void MyTest
{
Assert.IsTrue(true);
}
}

See also

  • Software testing
    Software testing
    Software testing is an investigation conducted to provide stakeholders with information about the quality of the product or service under test. Software testing can also provide an objective, independent view of the software to allow the business to appreciate and understand the risks of software...

  • Unit testing
  • Test-driven development
    Test-driven development
    Test-driven development is a software development process that relies on the repetition of a very short development cycle: first the developer writes a failing automated test case that defines a desired improvement or new function, then produces code to pass that test and finally refactors the new...

  • Mock object
    Mock object
    In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the...

  • List of Unit Testing Frameworks

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK