diff --git a/integrationtest/TargetProjects/NetCore/Library.FSharp.XUnit/Library.FSharp.XUnit.fsproj b/integrationtest/TargetProjects/NetCore/Library.FSharp.XUnit/Library.FSharp.XUnit.fsproj index b8d9d83ad..ec09f7212 100644 --- a/integrationtest/TargetProjects/NetCore/Library.FSharp.XUnit/Library.FSharp.XUnit.fsproj +++ b/integrationtest/TargetProjects/NetCore/Library.FSharp.XUnit/Library.FSharp.XUnit.fsproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true diff --git a/integrationtest/TargetProjects/NetCore/Library.FSharp/Library.FSharp.fsproj b/integrationtest/TargetProjects/NetCore/Library.FSharp/Library.FSharp.fsproj index 6dffa25b9..bb01451be 100644 --- a/integrationtest/TargetProjects/NetCore/Library.FSharp/Library.FSharp.fsproj +++ b/integrationtest/TargetProjects/NetCore/Library.FSharp/Library.FSharp.fsproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 diff --git a/src/Stryker.Core/Stryker.Core.UnitTest/TestRunners/VsTestRunnerPoolTests.cs b/src/Stryker.Core/Stryker.Core.UnitTest/TestRunners/VsTestRunnerPoolTests.cs index f0f0233cd..22ee4a81f 100644 --- a/src/Stryker.Core/Stryker.Core.UnitTest/TestRunners/VsTestRunnerPoolTests.cs +++ b/src/Stryker.Core/Stryker.Core.UnitTest/TestRunners/VsTestRunnerPoolTests.cs @@ -257,7 +257,7 @@ public void IdentifyNonCoveredMutants() } [TestMethod] - public void WorksWhenAllMutantsAreIgnoredPool() + public void ShouldIgnoreCoverageAnalysisWhenEmpty() { var options = new StrykerOptions { @@ -270,7 +270,7 @@ public void WorksWhenAllMutantsAreIgnoredPool() var analyzer = new CoverageAnalyser(options); analyzer.DetermineTestCoverage(SourceProjectInfo, runner, new[] { Mutant, OtherMutant }, TestGuidsList.NoTest()); - Mutant.CoveringTests.Count.ShouldBe(0); + Mutant.CoveringTests.IsEveryTest.ShouldBeTrue(); } [TestMethod] @@ -666,8 +666,9 @@ public void DetectUnexpectedCase() var mockVsTest = BuildVsTestRunnerPool(options, out var runner); + var testResult = BuildCoverageTestResult("T0", new[] { "0;", "" }); var buildCase = BuildCase("unexpected", TestFrameworks.NUnit); - SetupMockCoverageRun(mockVsTest, new[] { new VsTest.TestResult(buildCase) { Outcome = VsTest.TestOutcome.Passed } }); + SetupMockCoverageRun(mockVsTest, new[] { new VsTest.TestResult(buildCase) { Outcome = VsTest.TestOutcome.Passed }, testResult }); var analyzer = new CoverageAnalyser(options); analyzer.DetermineTestCoverage(SourceProjectInfo, runner, new[] { Mutant, OtherMutant }, TestGuidsList.NoTest()); diff --git a/src/Stryker.Core/Stryker.Core/CoverageAnalysis/CoverageAnalyser.cs b/src/Stryker.Core/Stryker.Core/CoverageAnalysis/CoverageAnalyser.cs index 152170f27..e10cb2a42 100644 --- a/src/Stryker.Core/Stryker.Core/CoverageAnalysis/CoverageAnalyser.cs +++ b/src/Stryker.Core/Stryker.Core/CoverageAnalysis/CoverageAnalyser.cs @@ -30,11 +30,7 @@ public void DetermineTestCoverage(IProjectAndTests project, ITestRunner runner, if (!_options.OptimizationMode.HasFlag(OptimizationModes.SkipUncoveredMutants) && !_options.OptimizationMode.HasFlag(OptimizationModes.CoverageBasedTest)) { - foreach (var mutant in mutants) - { - mutant.CoveringTests = TestGuidsList.EveryTest(); - mutant.AssessingTests = TestGuidsList.EveryTest(); - } + AssumeAllTestsAreNeeded(mutants); return; } @@ -42,9 +38,25 @@ public void DetermineTestCoverage(IProjectAndTests project, ITestRunner runner, ParseCoverage(runner.CaptureCoverage(project), mutants, new TestGuidsList(resultFailingTests.GetGuids())); } + private static void AssumeAllTestsAreNeeded(IEnumerable mutants) + { + foreach (var mutant in mutants) + { + mutant.CoveringTests = TestGuidsList.EveryTest(); + mutant.AssessingTests = TestGuidsList.EveryTest(); + } + } + private void ParseCoverage(IEnumerable coverage, IEnumerable mutantsToScan, TestGuidsList failedTests) { + if (coverage.Sum(c => c.MutationsCovered.Count) == 0) + { + _logger.LogError("It looks like the test coverage capture failed. Disable coverage based optimisation."); + AssumeAllTestsAreNeeded(mutantsToScan); + return; + } + var dubiousTests = new HashSet(); var trustedTests = new HashSet(); var testIds = new HashSet(); diff --git a/src/Stryker.Core/Stryker.Core/Initialisation/InitialisationProcess.cs b/src/Stryker.Core/Stryker.Core/Initialisation/InitialisationProcess.cs index 088cd0c9c..7a63c6a9f 100644 --- a/src/Stryker.Core/Stryker.Core/Initialisation/InitialisationProcess.cs +++ b/src/Stryker.Core/Stryker.Core/Initialisation/InitialisationProcess.cs @@ -158,7 +158,7 @@ private InitialTestRun InitialTest(IStrykerOptions options, SourceProjectInfo pr } throw new InputException( - "No test has been detected. Make sure your test project contains test and is compatible with VsTest." + + "No test result reported. Make sure your test project contains test and is compatible with VsTest." + string.Join(Environment.NewLine, projectInfo.Warnings)); }