- When you create a unit test, the name control of Microsoft. visualstudio. testtools. unittesting is added to the test project. The name control contains many useful classes:
- Assertion class: Validation conditions in Unit Tests
- Initialization and cleanup features: Used to run code before and after a unit test to ensure a specific start and end state
- Expectedexception feature: used to verify whether a specific type of exception is thrown during unit test execution
- Testcontext class: used to store information provided to unit tests and information required to run unit tests for ASP. NET web services. The system creates a variable named testcontextinstance for each test class.
- Testclassattribute: When you create a unit test, testclassattribute is included in the test file to indicate that this particular class can contain methods marked with the [testmethod ()] feature.
- Expectedexceptionattribute: Expected exception type
- Additional test features
- [Classinitialize ()]: You can use classinitialize to run the code before the first test of the running class.
- [Classcleanup ()]: You can use classcleanup to run the code after all tests in the class are run.
- [Testinitialize ()]: You can use testinitialize to run code before running each test.
- [Testcleanup ()]: Use testcleanup to run the code after each test is run.
- Roles of files in Test Solution
- Local. testsettings: these settings control how to run a local test that does not collect diagnostic data.
- Bank. vsmdi: This file contains information about the test list that exists in the solution and fills in the test List editor window.
- Traceandtestimpact. testsettings: these settings control how to run a local test that collects specific diagnostic datasets.
- How to configure and view test coverage
Double-click Local. testsettings, follow the configuration, and then click started without debugging to run the test project. You cannot run it directly using F5.
Visual Studio framework