TcUnit-VsTestAdapter makes it possible to execute TcUnit (TwinCAT unit tests) with the Microsoft Visual Studio Test Plattform
For more details see vstest test adapter extensibility
This section describes how to execute TcUnit tests in Azure DevOps pipelines or locally with Microsoft.TestPlatform.
It is also possible to run TcUnit tests on a VM that has vstest.console.exe installed.
Let's assume that the working folder is C:\Tools
.
-
Download and install NuGet.
-
Install NuGet package Microsoft.TestPlatform
nuget install Microsoft.TestPlatform
Find vstest.console.exe
in C:\Tools\Microsoft.TestPlatform.16.7.1\tools\net451\Common7\IDE\Extensions\TestPlatform
.
-
Install TcUnit.TestAdapter
nuget install TcUnit.TestAdapter
-
List all available tests (optional)
vstest.console.exe /ListTests /TestAdapterPath:C:\Tools\TcUnit.TestAdapter.1.0.0\lib\netstandard2.0 /Settings:path\to\TcUnit.runsettings *\*.tsproj
-
Start test run and execute available tests
vstest.console.exe /TestAdapterPath:C:\Tools\TcUnit.TestAdapter.1.0.0\lib\netstandard2.0 /Settings:path\to\TcUnit.runsettings *\*.tsproj
-
You may now create a *.cmd / *.ps1 file, put it inside your TcUnit tests project and run it after compile
See TwinCAT PLC Deployment for more information
-
Add NuGet tool installer task to install NuGet.exe.
Example:
steps: - task: NuGetToolInstaller@0 displayName: 'Use NuGet' inputs: versionSpec: 4.4.1
-
Add NuGet task. Set command to
custom
and specify the command line:install TcUnit.TestAdapter -Version $(TcUnitTestAdapterVersion)
Example
steps: - task: NuGetCommand@2 displayName: 'NuGet Install TcUnit.TestAdapter' inputs: command: custom arguments: 'install TcUnit.TestAdapter -Version $(TcUnitTestAdapterVersion)'
In the pipeline settings set TcUnitTestAdapterVersion variable to the TcUnit.TestAdapter version you want to install (e.g. 1.0.0). The task will install TcUnit.TestAdapter into
$(Build.Repository.LocalPath)\TcUnit.TestAdapter.$(TcUnitTestAdapterVersion)\lib\netstandard2.0
-
If you plan to run tests on a self-hosted Windows Agent that does not have Visual Studio installed you need to add Visual Studio Test Platform Installer task.
Example:
steps: - task: VisualStudioTestPlatformInstaller@1 displayName: 'Visual Studio Test Platform Installer' inputs: versionSelector: latestStable
-
To run tests you need Visual Studio Test task.
Example:
steps: - task: VSTest@2 displayName: 'VsTest - Run TcUnit Tests' inputs: testAssemblyVer2: | $(Build.Repository.LocalPath)\SolutionFolder\ProjectFolder\*.tsproj runSettingsFile: '$(System.DefaultWorkingDirectory)\.ci\TcUnit.runsettings' pathtoCustomTestAdapters: '$(Build.Repository.LocalPath)\TcUnit.TestAdapter.$(TcUnitTestAdapterVersion)\lib\netstandard2.0' platform: '$(BuildPlatform)' configuration: '$(BuildConfiguration)'
Make sure that path to custom test set adapters is set to
$(Build.Repository.LocalPath)\TcUnit.TestAdapter.$(TcUnitTestAdapterVersion)\lib\netstandard2.0
-
To publish test results (for later review and downloading) use Publish Build Artifacts task. Execution results are copied to
$(Agent.TempDirectory)\TestResults
.Example:
steps: - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: TestResults' inputs: PathtoPublish: '$(Agent.TempDirectory)\TestResults' ArtifactName: TestResults
TcUnit.TestAdapter supports filter
e.g. only executes the specific test
vstest.console.exe /TestAdapterPath:C:\Tools\TcUnit.TestAdapter.1.0.0\lib\netstandard2.0 /Settings:path\to\TcUnit.runsettings *\*.tsproj /TestCaseFilter:"FullyQualifiedName=UnitTests.AxisGeneric_Tests.Should_Fail_When_AxisIdIsZero"
Use custom run settings
vstest.console.exe /Settings:path\to\TcUnit.runsettings
.runsettings file is used to pass parameters to the test run.
see docs for detailed information
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<!-- Specify timeout in milliseconds. A valid value should be greater than 0 -->
<TestSessionTimeout>20000</TestSessionTimeout>
</RunConfiguration>
<TcUnit>
<Target>127.0.0.1.1.1</Target>
<CleanUpAfterTestRun>true</CleanUpAfterTestRun>
</TcUnit>
</RunSettings>