Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use mstest.exe without installing Visual Studio?

I want to use mstest.exe to run my unit test on build server, but I don't want to install Visual Studio on the build server. Can I just install MSTest without Visual Studio?

like image 528
yang-qu Avatar asked Aug 04 '10 05:08

yang-qu


People also ask

How do I run MSTest?

To access the MSTest tool, add the Visual Studio install directory to the path or open the Visual Studio Group from the Start menu, and then open the Tools section to access the Visual Studio command prompt. Use the command MSTest from the command prompt.

Does Visual Studio use MSTest or VSTest?

Visual Studio includes the VSTest and MSTest command-line tools for testing purposes. We can use both VSTEST and MSTEST to run automated unit and coded UI tests from a command line. 1.

Is MSTest a framework?

MSTest is a number-one open-source test framework that is shipped along with the Visual Studio IDE. It is also referred to as the Unit Testing Framework. However, MSTest is the same within the developer community. MSTest is used to run tests.


2 Answers

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 Agent on the server:

Visual Studio 2019
Visual Studio 2017 (127MB disk space, less than that for download)
Visual Studio 2015 and older: visit https://www.visualstudio.com/vs/older-downloads/ and follow the instructions

This installs everything needed for running mstest.exe from the command line and is much lighter weight than visual studio. ~500mb download and around ~300mb to install just the test agent if I remember correctly.

like image 79
Bela Avatar answered Nov 16 '22 00:11

Bela


This answer pertains specifically to Visual Studio 2017, and the answer is yes. Please refer to this answer as to how to locate the MSBuild.exe and/or MSTest.exe executables.

  • If you only need to build your unit test project(s), install the package MSTest.TestFramework into those project(s) and remove the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework from them. Now all you need is to install the Visual Studio 2017 Build Tools and invoke msbuild.exe to perform the build.
  • If you need to run your tests as well, things become trickier:
    • The simplest solution is to install VS2017 Community Edition (which includes both msbuild and mstest) - but I am unsure of the legality of this, and am not a lawyer, so be careful!
    • A legally safer solution (and far lighter, in terms of disk space) is to install the Visual Studio 2017 Test Agent and then Build Tools for Visual Studio 2017 (exact order is vital1); this will give you MSTest.exe and vstest.console.exe which you can then call out to. Do note that actually figuring out where these executables reside is a pain, because they won't exist in the same directory structure as MSBuild.exe in Build Tools.

Finally, and very importantly: if you do use MSTest.TestFramework and still need to be able to discover and run tests from within the Visual Studio IDE, you'll also need MSTest.TestAdapter installed in your unit test project(s).

1: While VS2017 supports side-by-side installs, it uses a single registry key that only records the most recent install. Hence, if you install Test Agent last, the key will point to its install directory... but Test Agent doesn't include MSBuild.exe, so any code that relies on this registry key to figure out that executable's path, will fail. Why Microsoft couldn't have made the Test Agent an optional part of Build Tools (so that all the EXEs live in the same directory hierarchy) is anyone's guess.

like image 20
Ian Kemp Avatar answered Nov 16 '22 01:11

Ian Kemp