question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The MSTest tool doesn't pick up the mstest.exe from Visual Studio 2017

See original GitHub issue

What You Are Seeing?

I run the unit tests like this:

MSTest("./src/**/bin/" + configuration + "/*.Tests.dll");

I get the following error when running the build script:

An error occurred when executing task 'Run-Unit-Tests'.
Error: MSTest: Could not locate executable.

What is Expected?

I expect my unit tests to run.

What version of Cake are you using?

0.17

Are you running on a 32 or 64 bit system?

64 bit

What environment are you running on? Windows? Linux? Mac?

Windows 10

Are you running on a CI Server? If so, which one?

No, just building on my local machine.

How Did You Get This To Happen? (Steps to Reproduce)

Run a build with unit tests on a machine with only Visual Studio 2017 (Community Edition).

Output Log

========================================
Run-Unit-Tests
========================================
Executing task: Run-Unit-Tests
An error occurred when executing task 'Run-Unit-Tests'.
Error: Cake.Core.CakeException: MSTest: Could not locate executable.
   at Cake.Core.Tooling.Tool`1.RunProcess(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings)
   at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action`1 postAction)
   at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments)
   at Cake.Common.Tools.MSTest.MSTestRunner.Run(IEnumerable`1 assemblyPaths, MSTestSettings settings)
   at Cake.Common.Tools.MSTest.MSTestAliases.MSTest(ICakeContext context, IEnumerable`1 assemblyPaths, MSTestSettings settings)
   at Cake.Common.Tools.MSTest.MSTestAliases.MSTest(ICakeContext context, IEnumerable`1 assemblyPaths)
   at Cake.Common.Tools.MSTest.MSTestAliases.MSTest(ICakeContext context, String pattern)
   at Submission#0.<.ctor>b__11()
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass5_0.<Does>b__0(ICakeContext context)
   at Cake.Core.ActionTask.Execute(ICakeContext context)
   at Cake.Core.DefaultExecutionStrategy.Execute(CakeTask task, ICakeContext context)
   at Cake.Core.CakeEngine.ExecuteTask(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
   at Cake.Core.CakeEngine.RunTarget(ICakeContext context, IExecutionStrategy strategy, String target)
   at Cake.Scripting.BuildScriptHost.RunTarget(String target)
   at Submission#0..ctor(Session session, Object& submissionResult)
   at Submission#0.<Factory>(Session session)
   at Roslyn.Scripting.CommonScriptEngine.Execute[T](String code, String path, DiagnosticBag diagnostics, Session session, Boolean isInteractive)
   at Roslyn.Scripting.Session.Execute(String code)
   at Cake.Scripting.Roslyn.Stable.DefaultRoslynScriptSession.Execute(Script script)
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments)
   at Cake.Commands.BuildCommand.Execute(CakeOptions options)
   at Cake.CakeApplication.Run(CakeOptions options)
   at Cake.Program.Main()

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
jnm2commented, Nov 3, 2017

Looking forward to the fix. This is the workaround I’ve been using:

// https://github.com/cake-build/cake/issues/1522
VSTestSettings FixToolPath(VSTestSettings settings)
{
    #tool vswhere
    settings.ToolPath =
        VSWhereLatest(new VSWhereLatestSettings { Requires = "Microsoft.VisualStudio.PackageGroup.TestTools.Core" })
        .CombineWithFilePath(File(@"Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"));
    return settings;
}

Then just wrap your settings:

VSTest("**/*.Tests.dll", FixToolPath(new VSTestSettings { Foo = 42 }))

(See https://github.com/Microsoft/vswhere/wiki/Find-VSTest.)

2reactions
robertmuehsigcommented, Mar 13, 2017

I had the same issue - as @phillipsj already mentioned, the ToolPath did the trick (even it is not super “clean”)

MSTest(pathPattern, new MSTestSettings() { ....
                                 ToolPath = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\MSTest.exe" });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I use mstest.exe without installing Visual Studio?
It is possible to run mstest.exe without visual studio. Download one of the Agents for Visual Studio ISO's below and install the Test...
Read more >
VSTest.Console.exe command-line options - Visual Studio ...
Learn about the VSTest.Console.exe command-line tool that runs tests. This article includes the General command-line options.
Read more >
Test Explorer not discoverying test methods
There is a bug either in MSTest or Nuget where the correct set of assemblies are not loaded, and that causes tests to...
Read more >
FAQs and Troubleshooting
What if unit tests using MSTest V1 framework are not executed? ... Why is dotTEST unable to find build artifacts in Visual Studio...
Read more >
Visual Studio Tests | TeamCity On-Premises Documentation
The Visual Studio Tests build runner integrates functionality of the MSTest ... Select the tool used to run tests: VSTest or MSTest.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found