use import="Json" use import="Environment" default NO_PARALLEL_TEST_PROJECTS='${E("NO_PARALLEL_TEST_PROJECTS")}' @{/* xunit-test Run unit tests in your project. projectFile='' Required. Path to the test project.json to execute */} @{ var projectText = File.ReadAllText(projectFile); var project = (JsonObject)Json.Deserialize(projectText); if (project.Keys.Contains("testRunner")) { var projectFolder = Path.GetDirectoryName(projectFile); var projectName = Path.GetFileName(projectFolder); var noParallelTestProjects = new HashSet(StringComparer.OrdinalIgnoreCase); if (!string.IsNullOrEmpty(NO_PARALLEL_TEST_PROJECTS)) { noParallelTestProjects.UnionWith(NO_PARALLEL_TEST_PROJECTS.Split((char)',')); } var testArgs = noParallelTestProjects.Contains(projectName) ? " -parallel none" : ""; var configs = project.ValueAsJsonObject("frameworks"); IEnumerable targetFrameworks = configs == null? new string[0]: configs.Keys.Where(k => k.StartsWith("dnx", StringComparison.OrdinalIgnoreCase)); var runnerFolder = Path.GetFullPath(Path.Combine(KoreBuildFolderPath, "build", "xunit.runner.console", "tools")); foreach (var framework in targetFrameworks) { if (!framework.StartsWith("dnxcore")) { if (IsLinux) { // Work around issue with testing in parallel on Mono. testArgs = " -parallel none"; } var publishFolder = Path.Combine(projectFolder, ".testPublish", framework); DotnetPublish(projectFile, publishFolder, framework); Copy(runnerFolder, publishFolder, "*.*", true); var targetTestDll = projectName + ".dll"; var runnerExe = Path.GetFullPath(Path.Combine(publishFolder, "xunit.console.exe")); ExecClr(runnerExe, targetTestDll + " " + testArgs, publishFolder); } } } }