2

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).
Josh Kodroff
  • 27,301
  • 27
  • 95
  • 148

1 Answers1

2

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>

Community
  • 1
  • 1
Timbo
  • 4,505
  • 2
  • 26
  • 29
  • Thanks! Any idea if this approach avoids the annoyance where msbuild evaluates file lists immediately when the build starts as opposed to when the target that uses the file list is actually run? (This means that when a new test assembly is added, the build has to be run twice in order to pick up the new assembly.) – Josh Kodroff Apr 08 '11 at 15:34
  • Haven't come across that issue, but have used similar configs, so possibly! :P – Timbo Apr 08 '11 at 15:36
  • It does fix that annoyance. That's why it's in a target instead of just an . – Josh Kodroff Apr 23 '11 at 17:30
  • Since 4.0 you can use an ItemGroup inside a target and it will have the same effect as using a CreateItem - i.e. it will only evaluate it when it gets to it. – Squirrel Jul 04 '14 at 14:36