Unit Testing for .NET
Synergy .NET supports unit testing for .NET Framework and .NET 6 and higher development.
- SDI adds the following to Visual studio: the “Unit Test Project (.NET Framework)” and “Unit Test (.NET)” project templates, and the “Basic Unit Test” and “Unit Test” item templates.
- For .NET CLI development, the Synergex.Projects.Templates NuGet package includes the synNETUnitTest project template (for .NET 6 and higher) and the synUnitTestProj project template (for .NET Framework). And the Synergex.ProjectItem.Templates NuGet package includes the synSimpleUnitTest and synUnitTest item templates.
- SDI uses the Visual Studio Unit Testing framework (MSTest), and Synergy unit tests integrate with Visual Studio’s Test Explorer. You can also use “dotnet test” and the VSTest.Console.exe command line tool to run unit tests.
|
A known issue with VSTest.Console.exe causes the following when a solution has both Synergy .NET Framework projects and Synergy .NET 6 or higher projects:
- Using VSTest.Console.exe or Test Explorer to run unit tests for a solution that has both types of projects will cause an error (FileNotFoundException for System.Runtime Version 4.2.2.0). To see this error in Test Explorer, go to the Test Explorer output window and select “Tests”.
- Building a solution with both types of projects will cause tests for Synergy .NET 6 and higher projects to disappear from Test Explorer. (If you subsequently rebuild only the Synergy .NET 6 and higher projects, the unit tests for those projects will reappear in Test Explorer.)
This VSTest.Console.exe issue affects Synergy unit tests in Test Explorer because Test Explorer uses VSTest.Console.exe behind the scenes for Synergy unit tests. For more information on this issue (which also affects unit tests for C# projects), see github.com/microsoft/vstest/issues/2310.
|
The following is the basic procedure for setting up and running unit tests in Visual Studio. See Microsoft documentation on unit tests (e.g., Unit test basics) for more information.
|
1.
|
Create unit test projects using one of the project templates listed above. Generally, you’ll create a unit test project for each Synergy .NET project in the solution. See Microsoft unit test documentation (e.g., Create a unit test project) for guidelines on creating unit tests. |
|
2.
|
In each unit test project, add a reference to the project(s) it will test. |
|
3.
|
Code the tests using MSTest attributes enclosed in curly brackets. (For Synergy, these attributes are enclosed in curly brackets rather than square brackets—for example: {TestMethod}) See Microsoft documentation for more information (e.g., see Use the MSTest framework in unit tests). |
|
4.
|
Run the unit tests from Test Explorer or from the command line (e.g., “dotnet test”). For more information, see Microsoft documentation, such as |