Executing tests from Visual Studio is as simple as running them from Test Explorer. Make sure that you follow the docs on creating test projects so the tests can show up.
In a CI environment you'd execute tests with the dotnet
command line tool. These are the steps we recommend for CI builds:
- Build the solution with
dotnet build
in Release mode. We recommend using our .NET Analyzers for static code analysis and applying the code analysis switches on this step and during thedotnet publish
ones later. - Publish the web app's project with
dotnet publish
in Release mode, optionally also with ReadyToRun. Note that since the web app shouldn't really reference your UI test projects this doesn't publish those. Remove or don't publish the refs folder. That way, Razor Runtime Compilation will be switched off, which removes an unnecessary and slow step when executing UI tests. - Publish the UI test project(s) with
dotnet publish
in Release mode. - Run the UI tests with
dotnet test
. Note that by default, the app will run in the Development environment, which is what we need for testing. - Optionally, if you want to reuse the build agent, kill the following processes that might remain after UI testing:
- chromedriver.exe
- dotnet.exe
- geckodriver.exe
- IEDriverServer.exe
- msedgedriver.exe
Also see what to configure, especially for multi-agent build machines and tuning parallelization.