GithubHelp home page GithubHelp logo

dotnet-samples's Introduction

.NET Test Samples

This is sample .NET solution for integrating with Universal Agent. It includes:

  1. Test projects that support .NET Core 2.2: xUnitSample, MSTestSample, NUnitSample
  2. Test project that support .NET 4.5 (Windows only): UnitTestSample

Follow these instructions for integrating with Universal Agent

  1. Integrate NUnit Test with Universal Agent
  2. Integrate MSTest with Universal Agent
  3. Integrate xUnit.net with Universal Agent
  4. Integrate .NET UnitTest with Universal Agent

Package Dependencies

  1. NunitXml.TestLogger to generate NUnit 3 format

  2. Selenium.WebDriver

  3. Selenium.Support

  4. Selenium.WebDriver.ChromeDriver (Win32, macOS, and Linux64)

.NET Core 2.2: xUnitSample, MSTestSample, NUnitSample project

Run tests on Command Prompt or Terminal

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:

  1. 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"
  1. 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"
  1. 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

.NET 4.5+: UnitTestSample project (Windows only)

Run tests on Command Prompt

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:

  1. 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"
  1. 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"
  1. 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

dotnet-samples's People

Contributors

huynguyenqas avatar imajeetyadav avatar phuthanhta avatar tamvanvo avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.