static void InvokeUnitTest(ParsedProject project, PlatformTarget platformTarget, AnyUnitTestSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } if (project == null) { throw new ArgumentNullException("project"); } var path = project.ProjectFile; var relativeProjectFile = Context.Environment.WorkingDirectory.GetRelativePath(path); // parse referenced dependencies. We assume that if you reference a unit-test dll in your project, then that project // in fact contains tests. But there are always exceptions, and thus we allow you to exclude projects as well. if (ExcludeFromUnitTests.Contains(project.Project.AssemblyName) || ExcludeFromUnitTests.Contains(project.Project.ProjectGuid) || ExcludeFromUnitTests.Contains(relativeProjectFile.ToString())) { Context.Log.Verbose(string.Format(" Skipping project {0} as it was explicitly excluded from testing.", relativeProjectFile)); return; } Context.Log.Information(string.Format("Searching for tests in {0} with platform {1}", relativeProjectFile, platformTarget)); var binDir = BuildActions.ComputeProjectBinPath(project); var testDir = ComputeProjectUnitTestPath(project); var testDll = binDir.CombineWithFilePath(ComputeTargetFile(project)); if (HasTestFramework(project, NUnit2Reference)) { Context.Log.Verbose(string.Format(" Testing with NUnit 2: {0}.", relativeProjectFile)); Context.CreateDirectory(testDir); Context.NUnit(new[] { testDll }, BuildNUnitSettings(project, settings, testDir)); } else if (HasTestFramework(project, NUnit3Reference)) { Context.Log.Verbose(string.Format(" Testing with NUnit 3: {0}.", relativeProjectFile)); Context.CreateDirectory(testDir); Context.NUnit3(new[] { testDll }, BuildNUnit3Settings(project, settings, testDir)); } else if (HasTestFramework(project, Xunit2Reference)) { Context.Log.Verbose(string.Format(" Testing with XUnit 2: {0}.", relativeProjectFile)); Context.CreateDirectory(testDir); Context.XUnit2(new[] { testDll }, BuildXUnit2Settings(project, settings, testDir)); var inputFile = testDir.CombineWithFilePath(project.Project.AssemblyName + ".xunit2.xml"); var outputFile = testDir.CombineWithFilePath(project.Project.AssemblyName + ".nunit2.xml"); Context.XmlTransform(Context.File("tools/xunit.runner.console/tools/NUnitXml.xslt"), inputFile, outputFile); } else if (HasTestFramework(project, Xunit1Reference)) { Context.Log.Verbose(string.Format(" Testing with XUnit 1: {0}.", relativeProjectFile)); Context.CreateDirectory(testDir); var xunitSettings = BuildXUnitSettings(project, settings, testDir); var xunitRunner = new FixedXUnitRunner(Context.FileSystem, Context.Environment, Context.ProcessRunner, Context.Tools); xunitRunner.Run(testDll, xunitSettings, settings.ForceX86 || project.Platform == PlatformTarget.x86); var inputFile = testDir.CombineWithFilePath(project.Project.AssemblyName + ".xunit.xml"); var outputFile = testDir.CombineWithFilePath(project.Project.AssemblyName + ".nunit2.xml"); Context.XmlTransform(Context.File("tools/xunit.runners/tools/NUnitXml.xslt"), inputFile, outputFile); } else { Context.Log.Verbose( string.Format(" Skipping project {0} as it does not reference a supported unit-testing framework.", relativeProjectFile)); } }