Running VSTS tests without mstest.exe

2019-02-02 11:37发布

问题:

From reasons I won't get into, all our unit tests are using the VSTS test framework. I now want to create an MSBuild script that runs the tests, but I don't want to use mstest.exe from various reasons (it's slower, requires Visual Studio installation everywhere, I need to maintain testrunconfig, etc.)

I've seen that TestDriven.net and TeamCity are able to run VSTS tests 'NUnit style', without using mstest.exe. Are you aware of any standalone command line utility that does this?

回答1:

You can execute Team System Tests (MSTest) in NUnit if you use a special NUnit Addin that recognizes the MS Test Attributes (TestClass, etc).

Exact Magic Software has an open-source "test-adapter" that can do this.

UPDATE: I've reworked Exact Magic's Msts NUnit Adapter for NUnit 2.5.2.

  • Download here: http://snippetware.googlecode.com/files/ExactMagic.MstsAdapter.zip
  • Read more about it here: http://www.bryancook.net/2009/10/mstest-nunit-adapter.html


回答2:

It seems like TeamCity is simply leveraging Gallio to run VS tests. Gallio appears to have msbuild integration and sounds perfect but after a closer look it seems that it would require a VS install just like MSTest as it appears to depend on MS exes:

The plugin enable condition was not satisfied: '${process:DEVENV.EXE} or 
${process:VSTESTHOST.EXE} or 
${process:QTAGENT.EXE} or 
${process:QTAGENT32.EXE} or 
${process:QTDCAGENT.EXE} or 
${process:QTDCAGENT32.EXE}'.
Host process exited with code: 0

That being said it sounds like at least one person has got it working:

Christoph De Baene - Running MSTest without Visual Studio



回答3:

It is possible to run MSTests without installing Visual Studio. See how-do-i-use-mstest-without-visual-studio.

I did this so that I could run my tests as part of my CI process. (I am using CC.NET for my CI solution).


I am in a similar situation as you, in that I want to use TestDriven.NET to get code coverage stats. But, I am running into problems. My first problem is that I am using AssemblyInitialize attributes to initialize a database connection. This isn't supported by NUnit so about half of my tests fail whereas they run fine under MSTest.

So, it seems that translating tests from one test framework to another has pitfalls. If you are aware of that, then go forth, but it might be better to try and keep consistent on one test framework.



回答4:

We run VSTS tests using msbuild TestToolsTask on a Cruise Control server. This does not use the MSTEST executable -- the condition you ask for -- but does use a variety of TFS dependencies.

Note that we are migrating tests off of the VSTS test framework for NUnit, mostly because we can create extensions for NUnit to perform useful tasks.