Created
August 13, 2018 12:37
-
-
Save chestercodes/a553a587c26f8c748922ca7028c694f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#tool "nuget:?package=Microsoft.TestPlatform&version=15.7.0" | |
#tool "nuget:?package=NUnitTestAdapter&version=2.1.1" | |
var target = Argument("target", "Default"); | |
var configuration = Argument("configuration", "Release"); | |
var buildDir = Directory("./src/Example/bin") + Directory(configuration); | |
var slnFile = "./src/Example.sln"; | |
var testDllPattern = "./src/**/*Tests.dll"; | |
Task("Clean").Does(() => | |
{ | |
CleanDirectory(buildDir); | |
}); | |
Task("Restore-NuGet-Packages").IsDependentOn("Clean").Does(() => | |
{ | |
NuGetRestore(slnFile); | |
}); | |
Task("Build").IsDependentOn("Restore-NuGet-Packages").Does(() => | |
{ | |
MSBuild(slnFile, settings => settings.SetConfiguration(configuration)); | |
}); | |
public string getNUnit2AdapterPath(){ | |
var nugetPaths = GetDirectories("./tools/NUnitTestAdapter*/tools"); | |
if(nugetPaths.Count == 0){ | |
throw new Exception("Cannot locate the NUnit2 test adapter. You might need to add '#tool \"nuget:?package=NUnitTestAdapter&version=2.1.1\"' to the top of your build.cake file."); | |
} | |
return nugetPaths.Last().ToString(); | |
} | |
Task("Run-Tests").IsDependentOn("Build").Does(() => | |
{ | |
var testSettings = new VSTestSettings{ | |
ToolPath = Context.Tools.Resolve("vstest.console.exe"), | |
TestAdapterPath = getNUnit2AdapterPath(), | |
// use the Trx Logger and a deterministic output file name | |
// to be able to import test results into a build orchestration tool (VSTS, Teamcity etc.). | |
ArgumentCustomization = arg => arg.Append("/logger:trx;LogFileName=VsTestResults.xml") | |
}; | |
VSTest(testDllPattern, testSettings); | |
}); | |
Task("Default").IsDependentOn("Run-Tests"); | |
RunTarget(target); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment