예제 #1
0
        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
        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);
        }