From 8fa85ca41245aa8b9e14a0648e68d2a4739df610 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Sun, 8 May 2022 22:03:16 +0100 Subject: [PATCH] (#23) Add support for integration tests Introduce a new argument, testExecutionType, which can be set to either unit, integration, or all, to control which test assemblies are exectued. This controls the TestAssemblyFilePattern, which sets the globbing pattern used to locate the test assemblies. The default for this will be unit tests, but when required, this can be set higher to execute additional tests. --- .../Content/parameters.cake | 29 +++++++++++++++++-- Chocolatey.Cake.Recipe/Content/testing.cake | 10 +++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index ace9ad1..2ab9b5c 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -18,6 +18,7 @@ public static class BuildParameters public static string PreReleaseLabelFilePath { get; private set; } public static string Target { get; private set; } public static string BuildCounter { get; private set; } + public static string TestExecutionType { get; private set; } public static string Configuration { get; private set; } public static string DeploymentEnvironment { get; private set;} public static Cake.Core.Configuration.ICakeConfiguration CakeConfiguration { get; private set; } @@ -44,7 +45,8 @@ public static class BuildParameters public static DirectoryPath SolutionDirectoryPath { get; private set; } public static DirectoryPath TestDirectoryPath { get; private set; } public static FilePath IntegrationTestScriptPath { get; private set; } - public static string TestFilePattern { get; private set; } + public static string TestAssemblyFilePattern { get; private set; } + public static string TestAssemblyProjectPattern { get; private set; } public static string Title { get; private set; } public static string ResharperSettingsFileName { get; private set; } public static string RepositoryOwner { get; private set; } @@ -160,6 +162,7 @@ public static class BuildParameters context.Information("RepositoryName: {0}", RepositoryName); context.Information("NugetConfig: {0} ({1})", NugetConfig, context.FileExists(NugetConfig)); context.Information("Build Counter: {0}", BuildCounter); + context.Information("Test Execution Type: {0}", TestExecutionType); context.Information("RestorePackagesDirectory: {0}", RestorePackagesDirectory); context.Information("ProductName: {0}", ProductName); context.Information("ProductDescription: {0}", ProductDescription); @@ -174,6 +177,8 @@ public static class BuildParameters context.Information("StrongNameDependentAssembliesInputPath: {0}", StrongNameDependentAssembliesInputPath); context.Information("ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken: {0}", ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken); context.Information("AssemblyNamesRegexPattern: {0}", AssemblyNamesRegexPattern); + context.Information("TestAssemblyFilePattern: {0}", TestAssemblyFilePattern); + context.Information("TestAssemblyProjectPattern: {0}", TestAssemblyProjectPattern); context.Information("UseChocolateyGuiStrongNameKey: {0}", UseChocolateyGuiStrongNameKey); context.Information("AllowedAssemblyName: {0}", string.Join(", ", AllowedAssemblyNames)); context.Information("TransifexEnabled: {0}", TransifexEnabled); @@ -206,7 +211,8 @@ public static class BuildParameters DirectoryPath solutionDirectoryPath = null, DirectoryPath rootDirectoryPath = null, DirectoryPath testDirectoryPath = null, - string testFilePattern = null, + string testAssemblyFilePattern = null, + string testAssemblyProjectPattern = null, string integrationTestScriptPath = null, string resharperSettingsFileName = null, string repositoryOwner = null, @@ -293,7 +299,6 @@ public static class BuildParameters SolutionDirectoryPath = solutionDirectoryPath ?? SourceDirectoryPath.Combine(Title); RootDirectoryPath = rootDirectoryPath ?? context.MakeAbsolute(context.Environment.WorkingDirectory); TestDirectoryPath = testDirectoryPath ?? sourceDirectoryPath; - TestFilePattern = testFilePattern; IntegrationTestScriptPath = integrationTestScriptPath ?? context.MakeAbsolute((FilePath)"test.cake"); ResharperSettingsFileName = resharperSettingsFileName ?? string.Format("{0}.sln.DotSettings", Title); RepositoryOwner = repositoryOwner ?? string.Empty; @@ -386,6 +391,24 @@ public static class BuildParameters Target = context.Argument("target", "Default"); BuildCounter = context.Argument("buildCounter", BuildProvider.Build.Number); + TestExecutionType = context.Argument("testExecutionType", "unit"); + + if (TestExecutionType == "unit") + { + TestAssemblyFilePattern = testAssemblyFilePattern ?? "/**/*[tT]ests.dll"; + TestAssemblyProjectPattern = testAssemblyProjectPattern ?? "/**/*[tT]ests.csproj"; + } + else if (TestExecutionType == "integration") + { + TestAssemblyFilePattern = testAssemblyFilePattern ?? "/**/*[tT]ests.[iI]ntegration.dll"; + TestAssemblyProjectPattern = testAssemblyProjectPattern ?? "/**/*[tT]ests.[iI]ntegration.csproj"; + } + else if (TestExecutionType == "all") + { + TestAssemblyFilePattern = testAssemblyFilePattern ?? "/**/*{[tT]ests|[tT]ests.[iI]ntegration}.dll"; + TestAssemblyProjectPattern = testAssemblyProjectPattern ?? "/**/*{[tT]ests|[tT]ests.[iI]ntegration}.csproj"; + } + Configuration = context.Argument("configuration", "Release"); DeploymentEnvironment = context.Argument("environment", "Release"); ForceContinuousIntegration = context.Argument("forceContinuousIntegration", false); diff --git a/Chocolatey.Cake.Recipe/Content/testing.cake b/Chocolatey.Cake.Recipe/Content/testing.cake index 14f3a99..c8acd5a 100644 --- a/Chocolatey.Cake.Recipe/Content/testing.cake +++ b/Chocolatey.Cake.Recipe/Content/testing.cake @@ -21,7 +21,7 @@ BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit") Information("Running OpenCover and NUnit..."); OpenCover(tool => { - tool.NUnit3(GetFiles(BuildParameters.Paths.Directories.PublishedNUnitTests + (BuildParameters.TestFilePattern ?? "/**/*[tT]ests.dll")), new NUnit3Settings { + tool.NUnit3(GetFiles(BuildParameters.Paths.Directories.PublishedNUnitTests + BuildParameters.TestAssemblyFilePattern), new NUnit3Settings { Work = BuildParameters.Paths.Directories.NUnitTestResults }); }, @@ -40,7 +40,7 @@ BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit") Information("Running NUnit..."); // OpenCover doesn't work on anything non-windows, so let's just run NUnit by itself - NUnit3(GetFiles(BuildParameters.Paths.Directories.PublishedNUnitTests + (BuildParameters.TestFilePattern ?? "/**/*[tT]ests.dll")), new NUnit3Settings { + NUnit3(GetFiles(BuildParameters.Paths.Directories.PublishedNUnitTests + BuildParameters.TestAssemblyFilePattern), new NUnit3Settings { Work = BuildParameters.Paths.Directories.NUnitTestResults }); } @@ -58,7 +58,7 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit") Information("Running OpenCover and xUnit..."); OpenCover(tool => { - tool.XUnit2(GetFiles(BuildParameters.Paths.Directories.PublishedxUnitTests + (BuildParameters.TestFilePattern ?? "/**/*[tT]ests.dll")), new XUnit2Settings { + tool.XUnit2(GetFiles(BuildParameters.Paths.Directories.PublishedxUnitTests + BuildParameters.TestAssemblyFilePattern), new XUnit2Settings { OutputDirectory = BuildParameters.Paths.Directories.xUnitTestResults, XmlReport = true, NoAppDomain = true @@ -79,7 +79,7 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit") Information("Running xUnit..."); // OpenCover doesn't work on anything non-windows, so let's just run xUnit by itself - XUnit2(GetFiles(BuildParameters.Paths.Directories.PublishedxUnitTests + (BuildParameters.TestFilePattern ?? "/**/*[tT]ests.dll")), new XUnit2Settings { + XUnit2(GetFiles(BuildParameters.Paths.Directories.PublishedxUnitTests + BuildParameters.TestAssemblyFilePattern), new XUnit2Settings { OutputDirectory = BuildParameters.Paths.Directories.xUnitTestResults, XmlReport = true, NoAppDomain = true @@ -107,7 +107,7 @@ BuildParameters.Tasks.DotNetCoreTestTask = Task("DotNetCoreTest") msBuildSettings.WithProperty("FrameworkPathOverride", frameworkPathOverride); } - var projects = GetFiles(BuildParameters.TestDirectoryPath + (BuildParameters.TestFilePattern ?? "/**/*Tests.csproj")); + var projects = GetFiles(BuildParameters.TestDirectoryPath + BuildParameters.TestAssemblyProjectPattern); // We create the coverlet settings here so we don't have to create the filters several times var coverletSettings = new CoverletSettings {