diff --git a/recipe/unit-testing.cake b/recipe/unit-testing.cake index 24094d0..3180389 100644 --- a/recipe/unit-testing.cake +++ b/recipe/unit-testing.cake @@ -5,10 +5,12 @@ public static class UnitTesting { static ICakeContext _context; + static IUnitTestRunner _runner; static UnitTesting() { _context = BuildSettings.Context; + _runner = BuildSettings.UnitTestRunner ?? new NUnitLiteRunner(); } public static void RunAllTests() @@ -17,9 +19,7 @@ public static class UnitTesting _context.Information($"Located {unitTests.Count} unit test assemblies."); var errors = new List(); - - var runner = BuildSettings.UnitTestRunner ?? new NUnitLiteRunner(); - + foreach (var testPath in unitTests) { var testFile = testPath.GetFilename(); @@ -30,7 +30,7 @@ public static class UnitTesting ? $"Running {testFile} under {runtime}" : $"Running {testFile}"); - int rc = runner.RunUnitTest(testPath); + int rc = _runner.RunUnitTest(testPath); var name = runtime != null ? $"{testFile}({runtime})" @@ -76,7 +76,9 @@ public static class UnitTesting { // Use default patterns to find unit tests - case insensitive because // we don't know how the user may have named test assemblies. - var defaultPatterns = new [] { "**/*.tests.dll", "**/*.tests.exe" }; + var defaultPatterns = _runner is NUnitLiteRunner + ? new[] { "**/*.tests.exe" } + : new[] { "**/*.tests.dll", "**/*.tests.exe" }; var globberSettings = new GlobberSettings { IsCaseSensitive = false }; foreach (string filePattern in defaultPatterns) foreach (var testPath in _context.GetFiles(BuildSettings.OutputDirectory + filePattern, globberSettings))