Skip to content

Instantly share code, notes, and snippets.

@AlexCuse
Created July 12, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexCuse/f8fb4899478c43d16cc809687f6424b4 to your computer and use it in GitHub Desktop.
Save AlexCuse/f8fb4899478c43d16cc809687f6424b4 to your computer and use it in GitHub Desktop.
Run multiple test projects
//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