23

I have a project in .NET Core and have built tests using xUnit. Now I wanted to run the test in deployment process. What I have done so far:

I used this command in commandline:

dotnet test [project address]  ... 

it is working but the problem is that this command get the .csproj file and not the dll.

I installed and used xunit.runner.console but its not working with .NET Core projects.

I used dotnet xunit command, this one also not helped while I cannot give it the dll it is also using the project folder.

What can I use to run my built test (dont want to build them again), any commandline tools that I can give my test dll as an input and it runs the test for me.

Bernard Vander Beken
  • 4,848
  • 5
  • 54
  • 76
Meysam
  • 555
  • 1
  • 3
  • 16

1 Answers1

41

You have several options here:

1. Use vstest command

dotnet vstest Foo.dll

to run tests from a dll. xUnit tests are supported. Documentation.

A single dll file only is not enough. Run dotnet vstest from your bin folder, which usually contains:

Foo.dll
Foo.deps.json
Foo.runtimeconfig.json
Foo.runtimeconfig.dev.json
Microsoft.Extensions.Logging.Test.dll
xunit.runner.reporters.netstandard15.dll
xunit.runner.utility.netstandard15.dll
xunit.runner.visualstudio.dotnetcore.testadapter.dll

This bin output is necessary to run the tests.

2. Skip the project build on test run

dotnet test --no-build
Community
  • 1
  • 1
Ilya Chumakov
  • 23,161
  • 9
  • 86
  • 114
  • 3
    the vstest is working fine and smoothly. Thanks for your answer it helped a lot. – Meysam Jun 19 '17 at 11:42
  • I use a task on TFS that execute vstest.console.exe (in the same way as odtnet vstest calls vstest.console.exe). If I call vstest.console.exe mytests.dll it does not work because in the folder containing my test there is not the nunit.framework.dll. These file is in fact referenced in the files .deps.json and .runtimeconfig.dev.json. But these file seems ignored by vstest.console.exe. How to load these files ? – gentiane Jul 03 '17 at 15:01
  • 1
    For people viewing this in recent years vstest has been superseded by dotnet test again: "The dotnet vstest command is superseded by dotnet test, which can now be used to run assemblies" – Alex KeySmith Mar 30 '21 at 20:56