Skip to content

Commit

Permalink
(#23) Add support for integration tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gep13 committed May 8, 2022
1 parent 878aa98 commit 8fa85ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
29 changes: 26 additions & 3 deletions Chocolatey.Cake.Recipe/Content/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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; }
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions Chocolatey.Cake.Recipe/Content/testing.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
},
Expand All @@ -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
});
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 8fa85ca

Please sign in to comment.