Created
July 12, 2016 13:17
-
-
Save AlexCuse/f8fb4899478c43d16cc809687f6424b4 to your computer and use it in GitHub Desktop.
Run multiple test projects
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
//All.Tests program.cs | |
public static int Main(string[] args) | |
{ | |
var basepath = "./"; | |
if (args.Length > 0) | |
{ | |
basepath = args[0]; | |
} | |
var results = NUnitRunner.Run(basepath, typeof (Web.Tests.TestPlaceHolder), typeof (TestPlaceHolder), typeof(Infrastructure.Implementation.Tests.TestPlaceHolder)); | |
return results ? 0 : 1; | |
} | |
//NUnitRunner | |
public static bool Run(string basePath = "./", params Type[] types) | |
{ | |
var passed = types.Aggregate(true, (current, type) => ExecuteTestSuite(type, basePath) && current); | |
if (passed) | |
{ | |
Console.ForegroundColor = ConsoleColor.Green; | |
Console.WriteLine("\n\n***** All Passed *****\n\n"); | |
Console.ResetColor(); | |
} | |
else | |
{ | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.WriteLine("\n\n***** Failures Encountered *****\n\n"); | |
Console.ResetColor(); | |
} | |
return passed; | |
} | |
public static bool ExecuteTestSuite(Type type, string basepath) | |
{ | |
var nUnitLiteOptions = new NUnitLiteOptions($"-result:{basepath}/{type.Namespace}.xml"); | |
nUnitLiteOptions.Validate(); | |
var result = new TextRunner(type.Assembly).Execute(new TextUI(new ColorConsoleWriter(), TextReader.Null, nUnitLiteOptions), nUnitLiteOptions); | |
return result == 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment