From 5b7f1b5640b8d6c424909af84a1e7cad5c188e78 Mon Sep 17 00:00:00 2001 From: Cyrille-Alexandre NDOUMBE Date: Thu, 10 Nov 2022 22:42:19 +0100 Subject: [PATCH] Added extension point to customize unit test behavior --- CHANGELOG.md | 1 + .../Components/IUnitTest.cs | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b25e643..15c6b31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added execution of `IPublish.Publish` target on `integration` workflow - Added `IHaveReport` component that can be used by pipelines that output reports of any kind (code coverage, performance tests, ...) - Added `IUnitTest.UnitTestsResultsDirectory` which defines where to output unit test result files +- Added `IUnitTest.ProjectUnitTestSettings` to customize/override the unit tests settings. - Added `IMutationTest.MutationTestResultsDirectory` which defines where to output mutation test result files - Added `IBenchmark.BenchmarkTestResultsDirectory` which defines where to output benchmarks test result files - Added `IPullRequest` component which extends `IGitFlow` and create pull requests instead or merging back to `develop` (respectiveley `main`) when finishing a feature / coldfix (resp. release / hotfix) branch. diff --git a/src/Candoumbe.Pipelines/Components/IUnitTest.cs b/src/Candoumbe.Pipelines/Components/IUnitTest.cs index a5e61c0..582bc73 100644 --- a/src/Candoumbe.Pipelines/Components/IUnitTest.cs +++ b/src/Candoumbe.Pipelines/Components/IUnitTest.cs @@ -6,6 +6,7 @@ using Nuke.Common.Tools.Coverlet; using Nuke.Common.Tools.DotNet; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -47,11 +48,9 @@ public interface IUnitTest : ICompile, IHaveTests, IHaveCoverage .Apply(UnitTestSettingsBase) .Apply(UnitTestSettings) .CombineWith(UnitTestsProjects, (cs, project) => cs.SetProjectFile(project) - .CombineWith(project.GetTargetFrameworks(), (setting, framework) => setting.SetFramework(framework) - .AddLoggers($"trx;LogFileName={project.Name}.trx") - .SetCoverletOutput(UnitTestResultsDirectory / $"{project.Name}.{framework}.xml"))), - completeOnFailure: true - ); + .CombineWith(project.GetTargetFrameworks(), (setting, framework) => setting.Apply(ProjectUnitTestSettingsBase, (project, framework)) + .Apply(ProjectUnitTestSettings, (project, framework)) + ))); TestResultDirectory.GlobFiles("*.trx") .ForEach(testFileResult => AzurePipelines.Instance?.PublishTestResults(type: AzurePipelinesTestResultsType.VSTest, @@ -79,4 +78,15 @@ public interface IUnitTest : ICompile, IHaveTests, IHaveCoverage /// Configures the Unit test target /// public Configure UnitTestSettings => _ => _; -} + + + internal Configure ProjectUnitTestSettingsBase => (settings, tuple) => settings.SetFramework(tuple.framework) + .AddLoggers($"trx;LogFileName={tuple.project.Name}.{tuple.framework}.trx") + .SetCoverletOutput(UnitTestResultsDirectory / $"{tuple.project.Name}.{tuple.framework}.xml"); + + /// + /// Configure / override unit test settings at project level + /// + Configure ProjectUnitTestSettings => (settings, tuple) => settings; + +} \ No newline at end of file