This is sample .NET solution for integrating with Universal Agent. It includes:
- Test projects that support .NET Core 2.2: xUnitSample, MSTestSample, NUnitSample
- Test project that support .NET 4.5 (Windows only): UnitTestSample
Follow these instructions for integrating with Universal Agent
- Integrate NUnit Test with Universal Agent
- Integrate MSTest with Universal Agent
- Integrate xUnit.net with Universal Agent
- Integrate .NET UnitTest with Universal Agent
-
NunitXml.TestLogger to generate NUnit 3 format
Open Terminal (or Command Prompt on Windows).
Navigate to the dotnet-samples directory.
Publish the test project so all the dependencies are generated in one place. Below command shows how to publish xUnitSample project:
dotnet publish DotnetCore/xUnitSample/xUnitSample.csproj
The command will publish the project to dotnet-samples/DotnetCore/xUnitSample/bin/Debug/netcoreapp2.2/publish directory
Also, since this project uses Selenium and publish
command does not automatically copy the chromedriver (or chromedriver.exe on Windows to the publish directory, execute this command to copy it to the publish directory.
Windows
copy DotnetCore\xUnitSample\bin\Debug\chromedriver.exe DotnetCore\xUnitSample\bin\Debug\netcoreapp2.2\publish
Linux/Mac
cp DotnetCore/xUnitSample/bin/Debug/chromedriver DotnetCore/xUnitSample/bin/Debug/netcoreapp2.2/publish
Now, run tests using any of these dotnet vstest command that fits your need. Below are some examples:
- Run all tests (classes and methods) in the test project and generate NUnit XML results
dotnet vstest DotnetCore/xUnitSample/bin/Debug/netcoreapp2.2/publish/xUnitSample.dll --logger:"nunit;LogFilePath=./test-results/regressiontest-results.xml"
- Run specific test class, e.g. BrowserTest, in the test project and generate NUnit XML result
dotnet vstest DotnetCore/xUnitSample/bin/Debug/netcoreapp2.2/publish/xUnitSample.dll /Tests:BrowserTest --logger:"nunit;LogFilePath=./test-results/browsertest-results.xml"
or UnitTest class only
dotnet vstest DotnetCore/xUnitSample/bin/Debug/netcoreapp2.2/publish/xUnitSample.dll /Tests:UnitTest --logger:"nunit;LogFilePath=./test-results/unittest-results.xml"
- Run only one test method of a test class in the test project, e.g. xUnitSample.UnitTest.FailingTest, and generate NUnit XML result
dotnet vstest DotnetCore/xUnitSample/bin/Debug/netcoreapp2.2/publish/xUnitSample.dll /Tests:xUnitSample.UnitTest.FailingTest --logger:"nunit;LogFilePath=./test-results/xUnitSample.UnitTest.FailingTest-results.xml"
The commands to run tests for MSTestSample, NUnitSample projects are similar to xUnitSample project, you just need to change the xUnitSample to MSTestSample or NUnitSample.
Refer to dotnet vstest documentation for more options regarding dotnet vstest command
Download Nuget CLI to restore the Nuget packages.
Navigate to the dotnet-samples directory. Open Command Prompt on Windows.
Run command to restore the packages
\path\to\nuget.exe restore \path\to\Dotnet-Samples.sln
Build the test project
"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" Dotnet-Samples.sln /p:Configuration=Debug /p:Platform="Any CPU"
Open Developer Command Prompt and type where vstest.console.exe
to find the location of vstest.console.exe, e.g "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow".
Set the path of vstest.console.exe to system environment variables. If you do not do this, you need to give the full path to vstest.console.exe in the below commands.
Now, run tests using any of these vstest.console.exe command that fits your need. Below are some examples:
- Run all tests (classes and methods) in the test project and generate NUnit XML results
vstest.console.exe Dotnet\UnitTestSample\bin\Debug\UnitTestSample.dll --logger:"nunit;LogFilePath=./test-results/regressiontest-results.xml"
- Run specific test class, e.g. BrowserTest, in the test project and generate NUnit XML result
vstest.console.exe Dotnet\UnitTestSample\bin\Debug\UnitTestSample.dll /Tests:ArithmeticCalculatorTest --logger:"nunit;LogFilePath=./test-results/arithmetic-calculator-test-results.xml"
- Run only one test method of a test class in the test project, e.g. xUnitSample.UnitTest.FailingTest, and generate NUnit XML result
vstest.console.exe Dotnet\UnitTestSample\bin\Debug\UnitTestSample.dll /Tests:ArithmeticCalculatorTest.PassingAdditionTest --logger:"nunit;LogFilePath=./test-results/test-result.xml"
Refer to vstest console documentation for more options regarding vstest.console.exe command