コード例 #1
0
ファイル: VsTestRunner.cs プロジェクト: lpraz/stryker-net
        private string GenerateRunSettings(int?timeout, bool forCoverage)
        {
            var targetFramework = _projectInfo.TestProjectAnalyzerResult.TargetFramework;

            var targetFrameworkVersion = Regex.Replace(targetFramework, @"[^.\d]", "");

            switch (targetFramework)
            {
            case string s when s.Contains("netcoreapp"):
                targetFrameworkVersion = $".NETCoreApp,Version = v{targetFrameworkVersion}";

                break;

            case string s when s.Contains("netstandard"):
                throw new ApplicationException("Unsupported targetframework detected. A unit test project cannot be netstandard!: " + targetFramework);

            default:
                targetFrameworkVersion = $"Framework40";
                break;
            }

            var needCoverage          = forCoverage && NeedCoverage();
            var dataCollectorSettings = needCoverage ? CoverageCollector.GetVsTestSettings() : "";
            var settingsForCoverage   = string.Empty;

            if (needCoverage)
            {
                if (_testFramework.HasFlag(TestFramework.nUnit))
                {
                    settingsForCoverage = "<CollectDataForEachTestSeparately>true</CollectDataForEachTestSeparately>";
                }

                if (_testFramework.HasFlag(TestFramework.xUnit))
                {
                    settingsForCoverage += "<DisableParallelization>true</DisableParallelization>";
                }
            }
            var timeoutSettings = timeout.HasValue ? $"<TestSessionTimeout>{timeout}</TestSessionTimeout>" : "";
            var runSettings     =
                $@"<RunSettings>
 <RunConfiguration>
  <MaxCpuCount>{_options.ConcurrentTestrunners}</MaxCpuCount>
  <TargetFrameworkVersion>{targetFrameworkVersion}</TargetFrameworkVersion>
  {timeoutSettings}
  {settingsForCoverage}
 </RunConfiguration>{dataCollectorSettings}
</RunSettings>";

            _logger.LogDebug("VsTest runsettings set to: {0}", runSettings);

            return(runSettings);
        }
コード例 #2
0
        private string GenerateRunSettings(int?timeout, bool forMutantTesting, bool forCoverage, Dictionary <int, IList <string> > mutantTestsMap)
        {
            var    projectAnalyzerResult  = _projectInfo.TestProjectAnalyzerResults.FirstOrDefault();
            var    targetFramework        = projectAnalyzerResult.TargetFramework;
            var    targetFrameworkVersion = projectAnalyzerResult.TargetFrameworkVersion;
            string targetFrameworkVersionString;

            switch (targetFramework)
            {
            case Initialisation.Framework.NetCore:
                targetFrameworkVersionString = $".NETCoreApp,Version=v{targetFrameworkVersion}";
                break;

            case Initialisation.Framework.NetStandard:
                throw new StrykerInputException("Unsupported targetframework detected. A unit test project cannot be netstandard!: " + targetFramework);

            default:
                targetFrameworkVersionString = $".NETFramework,Version=v{targetFrameworkVersion.ToString(2)}";
                break;
            }

            var needCoverage          = forCoverage && NeedCoverage();
            var dataCollectorSettings = (forMutantTesting || forCoverage) ? CoverageCollector.GetVsTestSettings(needCoverage, mutantTestsMap, CodeInjection.HelperNamespace) : "";
            var settingsForCoverage   = string.Empty;

            if (_testFramework.HasFlag(TestFramework.nUnit))
            {
                settingsForCoverage = "<CollectDataForEachTestSeparately>true</CollectDataForEachTestSeparately>";
            }

            if (_testFramework.HasFlag(TestFramework.xUnit))
            {
                settingsForCoverage += "<DisableParallelization>true</DisableParallelization>";
            }
            var timeoutSettings = timeout.HasValue ? $"<TestSessionTimeout>{timeout}</TestSessionTimeout>" + Environment.NewLine : string.Empty;
            // we need to block parallel run to capture coverage and when testing multiple mutants in a single run
            var optionsConcurrentTestrunners = (forCoverage || !_options.Optimizations.HasFlag(OptimizationFlags.DisableTestMix)) ? 1 : _options.ConcurrentTestrunners;
            var runSettings =
                $@"<RunSettings>
 <RunConfiguration>
{(targetFramework == Initialisation.Framework.NetClassic ? "<DisableAppDomain>true</DisableAppDomain>" : "")}
  <MaxCpuCount>{optionsConcurrentTestrunners}</MaxCpuCount>
  <TargetFrameworkVersion>{targetFrameworkVersionString}</TargetFrameworkVersion>{timeoutSettings}{settingsForCoverage}
<DesignMode>false</DesignMode>
<BatchSize>1</BatchSize>
 </RunConfiguration>{dataCollectorSettings}
</RunSettings>";

            _logger.LogDebug("VsTest run settings set to: {0}", runSettings);

            return(runSettings);
        }
コード例 #3
0
        private string GenerateRunSettings(int?timeout, bool forCoverage)
        {
            var    targetFramework        = _projectInfo.TestProjectAnalyzerResults.FirstOrDefault().TargetFramework;
            var    targetFrameworkVersion = _projectInfo.TestProjectAnalyzerResults.FirstOrDefault().TargetFrameworkVersion;
            string targetFrameworkVersionString;

            switch (targetFramework)
            {
            case Initialisation.Framework.NetCore:
                targetFrameworkVersionString = $".NETCoreApp,Version = v{targetFrameworkVersion}";
                break;

            case Initialisation.Framework.NetStandard:
                throw new StrykerInputException("Unsupported targetframework detected. A unit test project cannot be netstandard!: " + targetFramework);

            default:
                targetFrameworkVersionString = $".NETFramework,Version = v{targetFrameworkVersion}";
                break;
            }

            var needCoverage          = forCoverage && NeedCoverage();
            var dataCollectorSettings = needCoverage ? CoverageCollector.GetVsTestSettings() : "";
            var settingsForCoverage   = string.Empty;

            if (needCoverage)
            {
                if (_testFramework.HasFlag(TestFramework.nUnit))
                {
                    settingsForCoverage = "<CollectDataForEachTestSeparately>true</CollectDataForEachTestSeparately>";
                }

                if (_testFramework.HasFlag(TestFramework.xUnit))
                {
                    settingsForCoverage += "<DisableParallelization>true</DisableParallelization>";
                }
            }
            var timeoutSettings = timeout.HasValue ? $"<TestSessionTimeout>{timeout}</TestSessionTimeout>" : "";
            var runSettings     =
                $@"<RunSettings>
 <RunConfiguration>
  <MaxCpuCount>{_options.ConcurrentTestrunners}</MaxCpuCount>
  <TargetFrameworkVersion>{targetFrameworkVersionString}</TargetFrameworkVersion>
  {timeoutSettings}
  {settingsForCoverage}
 </RunConfiguration>{dataCollectorSettings}
</RunSettings>";

            _logger.LogDebug($"{RunnerId}: VsTest runsettings set to: {runSettings}");

            return(runSettings);
        }
コード例 #4
0
        public void ProperlyCaptureParams()
        {
            var collector = new CoverageCollector();

            var start = new TestSessionStartArgs
            {
                Configuration = CoverageCollector.GetVsTestSettings(true, null, "Stryker.Core.UnitTest.TestRunners")
            };
            var mock = new Mock <IDataCollectionSink>(MockBehavior.Loose);

            collector.Initialize(mock.Object);

            collector.TestSessionStart(start);
            collector.TestCaseStart(new TestCaseStartArgs(new TestCase("theTest", new Uri("xunit://"), "source.cs")));
            MutantControl.CaptureCoverage.ShouldBeTrue();
        }
コード例 #5
0
        private string GenerateRunSettings(int?timeout, bool forMutantTesting, bool forCoverage, Dictionary <int, IList <string> > mutantTestsMap)
        {
            var projectAnalyzerResult = _projectInfo.TestProjectAnalyzerResults.FirstOrDefault();
            var targetFramework       = projectAnalyzerResult.TargetFramework;

            var needCoverage          = forCoverage && NeedCoverage();
            var dataCollectorSettings = (forMutantTesting || forCoverage) ? CoverageCollector.GetVsTestSettings(needCoverage, mutantTestsMap, CodeInjection.HelperNamespace) : "";
            var settingsForCoverage   = string.Empty;

            if (_testFramework.HasFlag(TestFramework.nUnit))
            {
                settingsForCoverage = "<CollectDataForEachTestSeparately>true</CollectDataForEachTestSeparately>";
            }

            if (_testFramework.HasFlag(TestFramework.xUnit))
            {
                settingsForCoverage += "<DisableParallelization>true</DisableParallelization>";
            }
            var timeoutSettings = timeout.HasValue ? $"<TestSessionTimeout>{timeout}</TestSessionTimeout>" + Environment.NewLine : string.Empty;
            // we need to block parallel run to capture coverage and when testing multiple mutants in a single run
            var optionsConcurrentTestrunners = (forCoverage || !_options.Optimizations.HasFlag(OptimizationFlags.DisableTestMix)) ? 1 : _options.ConcurrentTestrunners;
            var runSettings =
                $@"<RunSettings>
 <RunConfiguration>
{(targetFramework == Framework.DotNetClassic ? "<DisableAppDomain>true</DisableAppDomain>" : "")}
  <MaxCpuCount>{optionsConcurrentTestrunners}</MaxCpuCount>
{timeoutSettings}
{settingsForCoverage}
<DesignMode>false</DesignMode>
<BatchSize>1</BatchSize>
 </RunConfiguration>
{dataCollectorSettings}
</RunSettings>";

            _logger.LogDebug("VsTest run settings set to: {0}", runSettings);

            return(runSettings);
        }
コード例 #6
0
        public void ProperlySelectMutant()
        {
            var collector = new CoverageCollector();

            var mutantMap = new Dictionary <int, IList <string> >()
            {
                [0] = new List <string>()
            };

            var start = new TestSessionStartArgs
            {
                Configuration = CoverageCollector.GetVsTestSettings(false, mutantMap, this.GetType().Namespace)
            };
            var mock = new Mock <IDataCollectionSink>(MockBehavior.Loose);

            collector.Initialize(mock.Object);

            collector.TestSessionStart(start);

            collector.TestCaseStart(new TestCaseStartArgs(new TestCase("theTest", new Uri("xunit://"), "source.cs")));

            MutantControl.ActiveMutant.ShouldBe(0);
        }