Unit Testing for .NET

Synergy .NET supports unit testing for .NET Framework and .NET 6 and higher development, and SDI includes the “Unit Test Project (.NET Framework)” and “Unit Test (.NET)” project templates for unit tests. SDI uses the Visual Studio Unit Testing framework (MSTest), and Synergy unit tests integrate with Visual Studio’s Test Explorer . You can also use the command line tools vstest.console.exe and dotnet to run unit tests.

Note

A known issue with vsttest.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 vsttest.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. Open the solution that you want to unit test.
2. Create unit test projects using the “Unit Test Project (.NET Framework)” or “Unit Test (.NET)” template.
3. In each unit test project, add a reference to the project(s) it will test.
4. Code the tests using MSTest attributes. See Microsoft documentation (e.g., see learn.microsoft.com/en-us/visualstudio/test/using-microsoft-visualstudio-testtools-unittesting-members-in-unit-tests), and note that for Synergy, attributes are enclosed in curly brackets (rather than square brackets)—for example: {TestMethod}.
5. Run the unit tests from Test Explorer or from the command line. For more information, see Microsoft documentation (e.g., learn.microsoft.com/en-us/visualstudio/test/run-unit-tests-with-test-explorer and learn.microsoft.com/en-us/visualstudio/test/vstest-console-options).