Can I use mstest.exe without installing Visual Stu

2019-01-12 16:51发布

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?

8条回答
家丑人穷心不美
2楼-- · 2019-01-12 17:21

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 2017 (127MB disk space, less than that for download)
Visual Studio 2015 (128MB setup, 2GB disk space required)
Visual Studio 2012 (224MB)
Visual Studio 2013 (287MB)
Visual Studio 2010 (515MB)

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.

UPDATE

For versions older than VS 2017, look here:

https://www.visualstudio.com/vs/older-downloads/

查看更多
叼着烟拽天下
3楼-- · 2019-01-12 17:21

I think you probably can, but its definitely not supported.

I've found this blog article written by someone who claims to have MSTest working without Visual Studio installed.

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-12 17:30

@crocpulsar, you need to install Visual Studio on your build server, but you do NOT need to buy an additional licence.

There are just way too many dependancies to getting build & MSTest to work without VS installed, and it is most definately not supported.

As long as the person who starts the build has a licence, you do not need one for the build server. This has been the case since the dark days of 2005, and as long as there is edition parity then you are OK.

If everyone in your team has Ultimate, then you are free to install it on the build server; but if one of your team member's has Premium, then you should ideally install Premium on the build server. This also enables lots of other bits like Code Coverage, Test Impact Analysis, and Architecture Validation among others.

查看更多
SAY GOODBYE
5楼-- · 2019-01-12 17:30

If you need to run mstest.exe webtest tool then you can install Visual Studio Enterprise trial and make sure to run it at least once (just start it) under account under which test will be running with nothing additional needs to be done. So if your test run under System account then you need to use something like below

PS C:\agent> psexec -s cmd.exe
C:\Windows\system32>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\mstest.exe"
Microsoft (R) Test Execution Command Line Tool Version 15.0.27520.0
Copyright (c) Microsoft Corporation. All rights reserved.

Please specify tests to run, or specify the /publish switch to publish results.
For switch syntax, type "MSTest /help"
查看更多
爷、活的狠高调
6楼-- · 2019-01-12 17:33

This answer pertains specifically to Visual Studio 2017, and the answer is yes. Please be aware, however, that Microsoft (still) doesn't provide any sort of official API for locating the relevant executables (MSBuild.exe and MSTest.exe), so you are stuck reading registry keys and/or probing various directories to locate these files. You've been warned.

  • 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.

查看更多
淡お忘
7楼-- · 2019-01-12 17:33

Here are the steps I took to get my build server to run MsTest without installing VS 2012:

  1. Created 'Mstest' directory folder in c:\dev.
  2. Copied 'Mstest.exe' and 'Mstest.exe.config' from C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE to 'Mstest' directory
  3. Copy Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll to 'Mstest' directory
  4. Created 'assemblies' directory in 'Mstest' folder
  5. Extracted all v11 Microsoft.VisualStudio.QualityTools.*.dlls from C:\Windows\assembly to 'Mstest/assemblies' directory
  6. Copy all 'v11' Microsoft.VisualStudio.QualityTools..dlls and Microsoft.VisualStudio.TestTools..dlls from C:\Windows\Microsoft.NET\assembly\GAC_MSIL to 'Mstest/assemblies'
  7. Copy all v11 Microsoft.VisualStudio.QualityTools..dlls and Microsoft.VisualStudio.TestTools..dll from C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies to 'Mstest/assemblies'
  8. Add 'assemblies' to the 'privatePath' attribute of in 'Mstest.exe.config'
  9. Export 'HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Microsoft/VisualStudio/11.0/Enterprise/QualityTools and apply it to hudson box.
  10. Copy QTAgent32.exe and QTAgent32.exe.config to 'MsTest' directory from C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
  11. Add 'assemblies' to the 'privatePath' attribute of in 'QTAgent32.exe.config'
  12. Copy 'msdia110.dll' from 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Packages\Debugger' to 'MsTest/assemblies'
  13. Register 'msdia110.dll' with c:/windows/syswow64/regsvr32.exe /i '../mstest/assemblies/msdia110.dll'(This threw an error, but for some reason it still worked. I ran it a couple times and tried different regsvr32.exe versions before I checked, but it's there in the registry)

  14. Add environment variable 'MSTEST_HOME' and set it to 'c:\dev\mstest\' or to your path. I used the environment variable in my build script.

Debugging MsTest execution error:

Add to 'MsTest.exe.config'

<system.diagnostics> 
  <trace autoflush="true" indentsize="4"> 
    <listeners> 
      <add name="EqtListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\MsTest.log" /> 
    </listeners> 
  </trace> 
  <switches> 
    <add name="EqtTraceLevel" value="Verbose" /> 
  </switches> 
</system.diagnostics>
查看更多
登录 后发表回答