The Visual Studio Unit Testing Framework describes Microsoft's suite of unit testing tools as integrated into some[1] 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.exe, from a command line.

Elements

edit

Test class

edit

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

edit

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

edit

An assertion 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

edit

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

edit

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

edit

References

edit
  1. ^ "Visual Studio 2010 Express – No tests, please". 13 April 2010.
edit

📚 Artikel Terkait di Wikipedia

List of unit testing frameworks

system level testing. Frameworks are grouped below. For unit testing, a framework must be the same language as the source code under test, and therefore

List of Visual Basic .NET software and tools

performance profiler for Visual Basic .NET NUnit Visual Studio Unit Testing Framework (MSTest) xUnit.net List of .NET libraries and frameworks List of C# software

Visual Studio

include: Unit testing, IntelliTest, Live Unit Testing, Test Explorer, CodeLens test indicators, code coverage analysis, Fakes. Visual Studio allows developers

Google Test

framework within the Visual Studio environment. Free and open-source software portal List of unit testing frameworks CppUnit Google Test v1.17.0 release notes

Azure DevOps Server

Azure DevOps Server, formerly known as Team Foundation Server (TFS) and Visual Studio Team System (VSTS), is a Microsoft product that provides version control

Test-driven development

of unit testing frameworks Mock object Programming by example Sanity check Self-testing code Software testing Transformation Priority Premise Unit testing

List of Python software

OS X software in Python. Robot Framework – generic test automation framework for acceptance testing and acceptance test-driven development (ATDD). Setuptools

List of COBOL software and tools

the Rational Software division of IBM Micro Focus Unit Testing Framework — integrated COBOL unit testing tool GnuCOBOL debug mode — command-line debugging