开发者

How can I change the unit tests that are run for a particular build configuration?

开发者 https://www.devze.com 2022-12-13 20:30 出处:网络
We have a Visual Studio 2008 solution with a large number of projects in it.For the current product, only some of thos开发者_开发技巧e projects are being used.

We have a Visual Studio 2008 solution with a large number of projects in it. For the current product, only some of thos开发者_开发技巧e projects are being used.

We've created a build configuration for that product so we don't have to build every project in the solution.

I want to be able to easily run all the unit tests that are relevant for this build. There are a large number of tests for projects we don't care about at this point. Because those projects aren't in the build, they won't be compiled and therefore we can't test them.

Is there an easier way to define which tests should be run rather than just picking and choosing them from the Test View?


Using the *.csproj file, open it in a text editor and add in your own MSBuild task to run the unit tests in an AfterBuild target. Something like:

<Target Name="AfterBuild">
   <Exec Command="mstest.exe /detail:errormessage /detail:errorstacktrace /runconfig:$(TestRunConfig) /testcontainer:[relative path to your test assembly DLL] /resultsfile:UnitTestResults.trx" />
</Target>


You could create some msbuild scripts which will only compile specific projects, and you can have a script for each scenario.

eg.

for 2 C# projects A and B, with 2 tests AT and BT:

<if condition="$(BuildA)"> <!-- If Building Project A -->
<csc ... "A" /> <!-- Build A project -->
</if>

<if condition="$(BuildA)"> <!-- If Building Project A -->
<csc ... "AT" /> <!-- Build AT project -->
<exec "AT" ... /> <!-- Run AT tests -->
</if>

Then run the tests that have been built.

0

精彩评论

暂无评论...
验证码 换一张
取 消