Josh Kodroff
Josh Kodroff

Reputation: 28121

What are best practices for managing multiple test assemblies in an msbuild file?

I have a solution with a few nunit test assemblies and several more in the works.

Right now, I'm running my nunit command in my msbuild file like so:

    <Exec Command="nunit-console src\Assembly1.Tests\bin\Debug\Assembly1.Tests.Tests.dll src\Assembly2.Tests\bin\Debug\Assembly2.Tests.Tests.dll src\Assembly3.Tests\bin\Debug\Assembly3.Tests.Tests.dll src\Assembly4.Tests\bin\Debug\Assembly4.Tests.Tests.dll" />

Clearly this is unreadable and sucks. So the question is how do I improve this? Specifically:

  1. Is there some way I can put the test assemblies in a list and get output equivalent to foreach(var assembly in testAssemblies) string.Format("src\\{0}\\bin\\debug\\{1}", assembly)
  2. Should I be running all of my tests in a single nunit-console command? I'm guessing yes because I want it all in a single output file, and a single command which returns 0 or non-zero (thus failing the build if non-zero).

Upvotes: 2

Views: 1113

Answers (1)

Timbo
Timbo

Reputation: 4533

Think the highest ranked answer on this question has what you need.

Specifically the target filter that allows you to specify all assemblies but also specify name filtering if there's some you don't want to run:

<Target Name="GetTestAssemblies">
<CreateItem
    Include="$(WorkingDir)\unittest\**\bin\$(Configuration)\**\*Test*.dll"
    AdditionalMetadata="TestContainerPrefix=/testcontainer:">
   <Output
       TaskParameter="Include"
       ItemName="TestAssemblies"/>
</CreateItem>

Upvotes: 2

Related Questions