Beispiel #1
0
    private static void TestProjectForTarget(BuildContext context, FilePath project, string framework)
    {
        string projectName = $"{project.GetFilenameWithoutExtension()}.{framework}";
        var    resultsPath = context.MakeAbsolute(Paths.TestResults.CombineWithFilePath($"{projectName}.results.xml"));

        var settings = new DotNetTestSettings
        {
            Framework       = framework,
            NoBuild         = true,
            NoRestore       = true,
            Configuration   = context.MsBuildConfiguration,
            TestAdapterPath = new DirectoryPath("."),
            Loggers         = new[] { $"trx;LogFileName={resultsPath}" }
        };

        var coverletSettings = new CoverletSettings
        {
            CollectCoverage         = true,
            CoverletOutputFormat    = CoverletOutputFormat.cobertura,
            CoverletOutputDirectory = Paths.TestResults,
            CoverletOutputName      = $"{projectName}.coverage.xml",
            Exclude = new List <string> {
                "[Servly*.UnitTests]*"
            }
        };

        context.DotNetTest(project.FullPath, settings, coverletSettings);
    }
Beispiel #2
0
    private static void TestProjectForTarget(BuildContext context, FilePath project, string framework)
    {
        var testResultsPath = Paths.TestOutput;
        var projectName     = $"{project.GetFilenameWithoutExtension()}.{framework}";
        var settings        = new DotNetTestSettings
        {
            Framework     = framework,
            NoBuild       = true,
            NoRestore     = true,
            Configuration = context.MsBuildConfiguration,
        };

        if (!context.IsRunningOnMacOs())
        {
            settings.TestAdapterPath = new DirectoryPath(".");
            var resultsPath = context.MakeAbsolute(testResultsPath.CombineWithFilePath($"{projectName}.results.xml"));
            settings.Loggers = new[] { $"nunit;LogFilePath={resultsPath}" };
        }

        var coverletSettings = new CoverletSettings
        {
            CollectCoverage         = true,
            CoverletOutputFormat    = CoverletOutputFormat.cobertura,
            CoverletOutputDirectory = testResultsPath,
            CoverletOutputName      = $"{projectName}.coverage.xml",
            Exclude = new List <string> {
                "[GitVersion*.Tests]*", "[GitTools.Testing]*"
            }
        };

        context.DotNetTest(project.FullPath, settings, coverletSettings);
    }
 public static DotNetTestSettings WithMemoryDumpAfter(this DotNetTestSettings settings, int timeoutInMinutes)
 {
     return(settings.SetProcessArgumentConfigurator(
                args =>
                args.Add("--blame-hang")
                .Add("--blame-hang-dump-type full")
                .Add($"--blame-hang-timeout {timeoutInMinutes}m")
                ));
 }
Beispiel #4
0
 IEnumerable <DotNetTestSettings> CoverSettings(DotNetTestSettings settings) =>
 TestBaseSettings(settings)
 .EnableCollectCoverage()
 .SetCoverletOutputFormat(CoverletOutputFormat.opencover)
 .SetExcludeByFile("*.Generated.cs")
 .CombineWith(TestProjects, (_, v) => _
              .SetProjectFile(v)
              .SetLogger($"trx;LogFileName={v.Name}.trx")
              .SetCoverletOutput(TestResultDirectory / $"{v.Name}.xml"));
Beispiel #5
0
        /// <summary>
        ///   <p>The <c>dotnet test</c> command is used to execute unit tests in a given project. Unit tests are console application projects that have dependencies on the unit test framework (for example, MSTest, NUnit, or xUnit) and the dotnet test runner for the unit testing framework. These are packaged as NuGet packages and are restored as ordinary dependencies for the project.</p>
        ///   <p>For more details, visit the <a href="https://docs.microsoft.com/en-us/dotnet/core/tools/">official website</a>.</p>
        /// </summary>
        /// <remarks>
        ///   <p>This is a <a href="http://www.nuke.build/docs/authoring-builds/cli-tools.html#fluent-apis">CLI wrapper with fluent API</a> that allows to modify the following arguments:</p>
        ///   <ul>
        ///     <li><c>&lt;projectFile&gt;</c> via <see cref="DotNetTestSettings.ProjectFile"/></li>
        ///     <li><c>--</c> via <see cref="DotNetTestSettings.RunSettings"/></li>
        ///     <li><c>--blame</c> via <see cref="DotNetTestSettings.BlameMode"/></li>
        ///     <li><c>--collect</c> via <see cref="DotNetTestSettings.DataCollector"/></li>
        ///     <li><c>--configuration</c> via <see cref="DotNetTestSettings.Configuration"/></li>
        ///     <li><c>--diag</c> via <see cref="DotNetTestSettings.DiagnosticsFile"/></li>
        ///     <li><c>--disable-parallel</c> via <see cref="DotNetTestSettings.DisableParallel"/></li>
        ///     <li><c>--filter</c> via <see cref="DotNetTestSettings.Filter"/></li>
        ///     <li><c>--force</c> via <see cref="DotNetTestSettings.Force"/></li>
        ///     <li><c>--force-evaluate</c> via <see cref="DotNetTestSettings.ForceEvaluate"/></li>
        ///     <li><c>--framework</c> via <see cref="DotNetTestSettings.Framework"/></li>
        ///     <li><c>--ignore-failed-sources</c> via <see cref="DotNetTestSettings.IgnoreFailedSources"/></li>
        ///     <li><c>--list-tests</c> via <see cref="DotNetTestSettings.ListTests"/></li>
        ///     <li><c>--lock-file-path</c> via <see cref="DotNetTestSettings.LockFilePath"/></li>
        ///     <li><c>--locked-mode</c> via <see cref="DotNetTestSettings.LockedMode"/></li>
        ///     <li><c>--logger</c> via <see cref="DotNetTestSettings.Logger"/></li>
        ///     <li><c>--no-build</c> via <see cref="DotNetTestSettings.NoBuild"/></li>
        ///     <li><c>--no-cache</c> via <see cref="DotNetTestSettings.NoCache"/></li>
        ///     <li><c>--no-dependencies</c> via <see cref="DotNetTestSettings.NoDependencies"/></li>
        ///     <li><c>--no-restore</c> via <see cref="DotNetTestSettings.NoRestore"/></li>
        ///     <li><c>--output</c> via <see cref="DotNetTestSettings.Output"/></li>
        ///     <li><c>--packages</c> via <see cref="DotNetTestSettings.PackageDirectory"/></li>
        ///     <li><c>--results-directory</c> via <see cref="DotNetTestSettings.ResultsDirectory"/></li>
        ///     <li><c>--runtime</c> via <see cref="DotNetTestSettings.Runtime"/></li>
        ///     <li><c>--settings</c> via <see cref="DotNetTestSettings.SettingsFile"/></li>
        ///     <li><c>--source</c> via <see cref="DotNetTestSettings.Sources"/></li>
        ///     <li><c>--test-adapter-path</c> via <see cref="DotNetTestSettings.TestAdapterPath"/></li>
        ///     <li><c>--use-lock-file</c> via <see cref="DotNetTestSettings.UseLockFile"/></li>
        ///     <li><c>--verbosity</c> via <see cref="DotNetTestSettings.Verbosity"/></li>
        ///     <li><c>/property</c> via <see cref="DotNetTestSettings.Properties"/></li>
        ///   </ul>
        /// </remarks>
        private (BlockingCollection <ILineOut>, int) DotNetTest(DotNetTestSettings toolSettings = null)
        {
            toolSettings = toolSettings ?? new DotNetTestSettings();
            ProcessStartInfo processStartInfo = SlugCmdProcess.GetDefaultProcessSettings();

            ToolSettingsToProcessInfoConverter.Convert(toolSettings, processStartInfo);
            SlugCmdProcess slugCmdProcess = new SlugCmdProcess("Dot Net Test", processStartInfo);

            slugCmdProcess.Execute(DotNetTest_OutputProcessor);

            return(slugCmdProcess.Output, slugCmdProcess.ExitCode);
        }
Beispiel #6
0
        /// <inheritdoc />
        public override void Run(BuildContext context)
        {
            var dockerComposeFiles = new [] { "./tests/simpleauth.stores.marten.acceptancetests/docker-compose.yml" };

            try
            {
                context.Log.Information("Docker compose up");
                context.Log.Information("Ensuring test report output");

                context.EnsureDirectoryExists(context.Environment.WorkingDirectory.Combine("artifacts").Combine("testreports"));

                var upsettings = new DockerComposeUpSettings
                {
                    DetachedMode = true,
                    Files        = dockerComposeFiles
                };
                context.DockerComposeUp(upsettings);

                var project = new FilePath(
                    "./tests/simpleauth.stores.marten.acceptancetests/simpleauth.stores.marten.acceptancetests.csproj");
                context.Log.Information("Testing: " + project.FullPath);
                var reportName = "./artifacts/testreports/"
                                 + context.BuildVersion
                                 + "_"
                                 + System.IO.Path.GetFileNameWithoutExtension(project.FullPath) !.Replace('.', '_')
                                 + ".xml";
                reportName = System.IO.Path.GetFullPath(reportName);

                context.Log.Information(reportName);

                var coreTestSettings = new DotNetTestSettings()
                {
                    NoBuild   = true,
                    NoRestore = true,
                    // Set configuration as passed by command line
                    Configuration         = context.BuildConfiguration,
                    ArgumentCustomization = x => x.Append("--logger \"trx;LogFileName=" + reportName + "\"")
                };

                context.DotNetTest(project.FullPath, coreTestSettings);
            }
            finally
            {
                context.Log.Information("Docker compose down");

                var downsettings = new DockerComposeDownSettings
                {
                    Files = dockerComposeFiles
                };
                context.DockerComposeDown(downsettings);
            }
        }
Beispiel #7
0
        public static DotNetTestSettings AddTeamCityLogger(this DotNetTestSettings toolSettings)
        {
            ControlFlow.Assert(TeamCity.Instance != null, "TeamCity.Instance != null");
            var teamcityPackage = NuGetPackageResolver
                                  .GetLocalInstalledPackage("TeamCity.Dotnet.Integration", ToolPathResolver.NuGetPackagesConfigFile)
                                  .NotNull("teamcityPackage != null");
            var loggerPath = teamcityPackage.Directory / "build" / "_common" / "vstest15";

            ControlFlow.Assert(Directory.Exists(loggerPath), $"Directory.Exists({loggerPath})");
            return(toolSettings
                   .SetLogger("teamcity")
                   .SetTestAdapterPath(loggerPath));
        }
Beispiel #8
0
        private DotNetTestSettings CreateTestSettings(string unitTestProject, string testResultFile)
        {
            var settings = new DotNetTestSettings()
                           .SetProjectFile(unitTestProject)
                           .SetConfiguration(BuildInfo.Configuration)
                           .SetLoggers($"{_logger};LogFileName={testResultFile}");

            if (_enableCodeCoverage)
            {
                return(settings
                       .SetDataCollector("XPlat Code Coverage")
                       .SetResultsDirectory(_coverageDirectory));
            }

            return(settings);
        }
    public static void DotNetTest(
        this ICakeContext context,
        FilePath project,
        DotNetTestSettings settings,
        CoverletSettings coverletSettings)
    {
        if (context == null)
        {
            throw new ArgumentNullException(nameof(context));
        }
        var currentCustomization = settings.ArgumentCustomization;

        settings.ArgumentCustomization = (args) => ArgumentsProcessor.ProcessMSBuildArguments(
            coverletSettings,
            context.Environment,
            currentCustomization?.Invoke(args) ?? args,
            project);

        context.DotNetTest(project.FullPath, settings);
    }
Beispiel #10
0
        /// <summary>
        /// Run Unit Test Runner Process
        /// </summary>
        /// <returns></returns>
        protected override StageCompletionStatusEnum ExecuteProcess()
        {
            if (CISession.SkipTests)
            {
                return(StageCompletionStatusEnum.Skipped);
            }

            FileSystemTasks.EnsureExistingDirectory(CISession.CoveragePath);

            DotNetTestSettings settings = new DotNetTestSettings()
            {
                ProjectFile                 = CISession.Solution,
                Configuration               = CISession.CompileConfig,
                NoRestore                   = true,
                NoBuild                     = true,
                Verbosity                   = DotNetVerbosity.Minimal,
                ProcessLogOutput            = true,
                ResultsDirectory            = CISession.TestOutputPath,
                ProcessArgumentConfigurator = arguments => arguments.Add("/p:CollectCoverage={0}", true)
                                              .Add("", false)
                                              .Add("/p:CoverletOutput={0}/", CISession.CoveragePath)
                                              .Add("/p:CoverletOutputFormat={0}", "cobertura")
                                              .Add("/p:Threshold={0}", CISession.SlugCIConfigObj.CodeCoverageThreshold)
                                              .Add("/p:SkipAutoProps={0}", true)
                                              .Add("/p:ExcludeByAttribute={0}",
                                                   "\"Obsolete%2cGeneratedCodeAttribute%2cCompilerGeneratedAttribute\"")
                                              .Add("/p:UseSourceLink={0}", true)
            };


            (BlockingCollection <ILineOut> outputs, int exitCode) = DotNetTest(settings);
            StageOutput.AddRange(outputs);
            if (exitCode > 0 && CISession.FailedUnitTestsOkay)
            {
                AOT_Warning("One or more unit tests failed.  HOWEVER, the Failed Unit Tests Okay flag was set, so this is not stopping the CI process");
                return(StageCompletionStatusEnum.Warning);
            }

            return(StageCompletionStatusEnum.Success);
        }
 public static DotNetTestSettings EnableTrxLogOutput(this DotNetTestSettings settings, string resultsDirectory)
 {
     return(settings
            .SetLogger("trx")
            .SetResultsDirectory(resultsDirectory));
 }
 public static DotNetTestSettings SetTargetPlatform(this DotNetTestSettings settings, MSBuildTargetPlatform platform)
 {
     return(platform is null
         ? settings
         : settings.SetProperty("Platform", GetTargetPlatform(platform)));
 }
 public static DotNetTestSettings SetTargetPlatformAnyCPU(this DotNetTestSettings settings)
 => settings.SetTargetPlatform(MSBuildTargetPlatform.MSIL);
Beispiel #14
0
 DotNetTestSettings TestBaseSettings(DotNetTestSettings settings) =>
 settings
 .SetConfiguration(Configuration.Debug)
 .SetNoRestore(InvokedTargets.Contains(Restore))
 .ResetVerbosity()
 .SetResultsDirectory(TestResultDirectory);
Beispiel #15
0
 IEnumerable <DotNetTestSettings> TestSettings(DotNetTestSettings settings) =>
 TestBaseSettings(settings)
 .CombineWith(TestProjects, (_, v) => _
              .SetProjectFile(v)
              .SetLogger($"trx;LogFileName={v.Name}.trx"));