Unit Testing for .NET

Synergy .NET supports unit testing for .NET Framework and .NET 6 and higher development.

Note

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., learn.microsoft.com/en-us/visualstudio/test/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., learn.microsoft.com/en-us/visualstudio/test/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 learn.microsoft.com/en-us/visualstudio/test/using-microsoft-visualstudio-testtools-unittesting-members-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