23

I'm trying to run .NET unit tests on the command line using MSTest

My command is

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcontainer:"full path of dll" /resultsfile:TestResults.trx

When run it returns

Starting execution...
No tests to execute.

The unit test runs perfectly fine in VS 2012 IDE.

What do I need to do to get it running on the cmd line please?

7 Answers 7

35

In my case I started getting "No tests to execute" on command line when I switched to .NET Framework 4.6.1. I had to switch from MSTest.exe to VSTest.Console.exe for it to work.

Some instructions on how to use vstest.console.exe are here - https://msdn.microsoft.com/en-us/library/jj155800.aspx

Also check this out - https://msdn.microsoft.com/en-us/library/ms182486.aspx

2
  • Thank you, this was actually what helped me go through this. I'm using .NET Framework 4.6+ Apr 9, 2020 at 20:57
  • In case you use .NET Core, the command is: dotnet test my.tests.assembly.dll
    – Mladen B.
    May 19, 2020 at 14:52
6

It turns out I needed to use the nunit-console as my tests are written in the nunit framework.

Live and learn I guess

5
  1. Create a .Net Framework unit test project.

  2. Manage nuget packages -> Remove "MSTest.TestFramework" and "MSTest.TestAdapter" nuget packages.

  3. Add an assembly reference to "Microsoft.VisualStudio.QualityTools.UnitTestFramework", 10.0.0.0.

  4. Rebuild the project and verify that the output path(bin\debug) does not have any _MSTest_TestAdapter*.dll assemblies This works for me.

0
3

I was getting same message "No tests to execute".

What I found out was a silly mistake on my part - in command line, I was using MVCProj09292016.dll(my project DLL) for testcontainer:/ instead of using MVCProj09292016.Tests.dll(my test project assembly).

Bottom line is that check whether you are using correct dl name in command line:it should be your MStest project assembly, in my case it is MVCProj09292016.Tests.dll

1

Try using vstest.console.exe


Example:


vstest.console.exe [assembly.dll] /logger:trx;LogFileName=[filename].trx

1.Open Cross tools command prompt (use windows search)
Choose: Cross Tools Command Prompt for VS 2009

[1]
enter image description here
2. Open the Cross Tools Command line.
3. Navigate to your project's Bin folder
4. Copy/Paste your Bin folder's patch inside Cross Tools Command Line
Example:

enter image description here Than run the following command:
vstest.console.exe [assembly.dll] /logger:trx;LogFileName=[filename].trx

0

I had the same issue when I was using XUnit. The problem was that I didn't had included xunit.runner for the project. It's not very obvious, since it only adds a reference to packages.config and csproj-file. It's not visible in Visual Studio references list. It is still obvious in a way that without a runner, how does the mstest know how to run xunit tests.

1
  • How can you know whether or not you have included xunit in your project? In my case I have a solution, containing all test projects, and while entering xunit in the Solution Explorer, I see nothing.
    – Dominique
    Apr 16, 2018 at 8:11
-2

Try this:

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcontainer:full path of dll /resultsfile:TestResults.trx

Ie without the " " around your path to the dll

6
  • 5
    It solves my problem in the sense that it throws a different error now. It seems to been complaining about spaces in the directory name. Thanks
    – mogoli
    Apr 21, 2016 at 13:26
  • 2
    So I tried it with out the speech marks and moved my project to a directory with no spaces but it still says "No tests to execute."
    – mogoli
    Apr 21, 2016 at 14:00
  • "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcontainer:full\\path\\to\\dll /resultsfile:TestResults.trx
    – mogoli
    Apr 21, 2016 at 14:02
  • 2
    Note that this does only work with the .Net Framework, not with .NetCore or .NetStandard! Check out my answer here: stackoverflow.com/a/52964726/5536006 Oct 24, 2018 at 8:54
  • 2
    FranzHuber23 is correct. For .Net Core, you just instead run dotnet test MY_UNIT_TEST_PROJECT.csproj.
    – FoggyDay
    Feb 25, 2020 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.