public (IDictionary <Guid, VsTestDescription>, TestSet) DiscoverTests(string runSettings) { if (_vsTests != null) { return(_vsTests, _tests); } using (var waitHandle = new AutoResetEvent(false)) { var handler = new DiscoveryEventHandler(waitHandle, _messages); var generateRunSettings = GenerateRunSettings(null, false, false, null); _vsTestConsole.DiscoverTests(_sources, runSettings ?? generateRunSettings, handler); waitHandle.WaitOne(); if (handler.Aborted) { _logger.LogError($"{RunnerId}: Test discovery has been aborted!"); } _vsTests = new Dictionary <Guid, VsTestDescription>(handler.DiscoveredTestCases.Count); foreach (var testCase in handler.DiscoveredTestCases) { if (!_vsTests.ContainsKey(testCase.Id)) { _vsTests[testCase.Id] = new VsTestDescription(testCase); } _vsTests[testCase.Id].AddSubCase(); } DetectTestFramework(_vsTests.Values); } _tests.RegisterTests(_vsTests.Values.Select(t => t.Description)); return(_vsTests, _tests); }
public void FilterMutants_FiltersNoMutants_IfTestsChanged() { // Arrange var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); var options = new StrykerOptions() { WithBaseline = false, ProjectVersion = "version" }; diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedSourceFiles = new List <string>(), ChangedTestFiles = new List <string> { "C:/testfile1.cs" } }); var tests = new TestSet(); var test1 = new TestDescription(Guid.NewGuid(), "name1", "C:/testfile1.cs"); var test2 = new TestDescription(Guid.NewGuid(), "name2", "C:/testfile2.cs"); tests.RegisterTests(new[] { test1, test2 }); diffProvider.SetupGet(x => x.Tests).Returns(tests); var target = new SinceMutantFilter(diffProvider.Object); var testFile1 = new TestsGuidList(new [] { test1 }); var testFile2 = new TestsGuidList(new [] { test2 }); var expectedToStay1 = new Mutant { CoveringTests = testFile1 }; var expectedToStay2 = new Mutant { CoveringTests = testFile1 }; var newMutant = new Mutant { CoveringTests = testFile2 }; var mutants = new List <Mutant> { expectedToStay1, expectedToStay2, newMutant }; // Act var results = target.FilterMutants(mutants, new CsharpFileLeaf(), options); // Assert results.ShouldBe(new [] { expectedToStay1, expectedToStay2 }); }
public void ShouldNotFilterMutantsWhereCoveringTestsContainsChangedTestFile() { // Arrange var testProjectPath = "C:/MyTests"; var options = new StrykerOptions(); var diffProvider = new Mock <IDiffProvider>(MockBehavior.Loose); // If a file inside the test project is changed, a test has been changed var myTestPath = Path.Combine(testProjectPath, "myTest.cs");; var tests = new TestSet(); var test = new TestDescription(Guid.NewGuid(), "name", myTestPath); tests.RegisterTests(new[] { test }); diffProvider.SetupGet(x => x.Tests).Returns(tests); diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult { ChangedSourceFiles = new Collection <string> { myTestPath }, ChangedTestFiles = new Collection <string> { myTestPath } }); var target = new SinceMutantFilter(diffProvider.Object); // check the diff result for a file not inside the test project var file = new CsharpFileLeaf { FullPath = Path.Combine("C:/NotMyTests", "myfile.cs") }; var mutant = new Mutant { CoveringTests = new TestsGuidList(new[] { test }) }; // Act var filterResult = target.FilterMutants(new List <Mutant> { mutant }, file, options); // Assert filterResult.ShouldContain(mutant); }