public void It_builds_the_project_before_running()
        {
            var testCommand = new DotnetTestCommand();
            var result      = testCommand.Execute($"{_projectFilePath}");

            result.Should().Pass();
        }
        public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
        {
            // Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
            string       testAppName  = "VSTestDotNetCore";
            TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);

            string testProjectDirectory = testInstance.TestRoot;

            // Restore project VSTestDotNetCore
            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            string configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
            string expectedError = Path.Combine(testProjectDirectory, "bin",
                                                configuration, "netcoreapp1.0", "VSTestDotNetCore.dll");

            expectedError = "The test source file " + "\"" + expectedError + "\"" + " provided was not found.";

            // Call test
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput("--no-build");

            // Verify
            result.StdOut.Should().Contain(expectedError);
        }
예제 #3
0
        public void ItCreatesTrxReportInTheSpecifiedResultsDirectoryByArgs()
        {
            // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests
            var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("7");

            string trxLoggerDirectory = Path.Combine(testProjectDirectory, "RD");

            // Delete trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }

            // Call test with logger enable
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput("--logger \"trx;logfilename=custom.trx\" -- RunConfiguration.ResultsDirectory=" + trxLoggerDirectory);

            // Verify
            var trxFilePath = Path.Combine(trxLoggerDirectory, "custom.trx");

            Assert.True(File.Exists(trxFilePath));
            result.StdOut.Should().Contain(trxFilePath);

            // Cleanup trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }
        }
        public void ItTestsWithTheSpecifiedRuntimeOption()
        {
            var testInstance = _testAssetsManager.CopyTestAsset("XunitCore")
                               .WithSource()
                               .WithVersionVariables();

            var rootPath = testInstance.Path;
            var rid      = EnvironmentInfo.GetCompatibleRid();

            new DotnetBuildCommand(Log)
            .WithWorkingDirectory(rootPath)
            .Execute("--runtime", rid)
            .Should()
            .Pass()
            .And.NotHaveStdErr();

            var result = new DotnetTestCommand(Log, ConsoleLoggerOutputNormal)
                         .WithWorkingDirectory(rootPath)
                         .Execute("--no-build", "--runtime", rid);

            result
            .Should()
            .NotHaveStdErrContaining("MSB1001")
            .And
            .HaveStdOutContaining(rid);

            if (!TestContext.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Failed: 1");
            }

            result.ExitCode.Should().Be(1);
        }
        public void ItImplicitlyRestoresAProjectWhenTesting()
        {
            string testAppName  = "VSTestCore";
            var    testInstance = _testAssetsManager.CopyTestAsset(testAppName)
                                  .WithSource()
                                  .WithVersionVariables();

            var testProjectDirectory = testInstance.Path;

            CommandResult result = new DotnetTestCommand(Log)
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .Execute(ConsoleLoggerOutputNormal);

            if (!TestContext.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Total tests: 2");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Failed: 1");
                result.StdOut.Should().Contain("\u221a VSTestPassTest");
                result.StdOut.Should().Contain("X VSTestFailTest");
            }

            result.ExitCode.Should().Be(1);
        }
        public void XunitSingleTFM()
        {
            // Copy XunitCore project in output directory of project dotnet-vstest.Tests
            string testAppName  = "XunitCore";
            var    testInstance = _testAssetsManager.CopyTestAsset(testAppName, identifier: "4")
                                  .WithSource()
                                  .WithVersionVariables();

            var testProjectDirectory = testInstance.Path;

            // Restore project XunitCore
            new RestoreCommand(Log, testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            // Call test
            CommandResult result = new DotnetTestCommand(Log)
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .Execute(ConsoleLoggerOutputNormal);

            // Verify
            if (!TestContext.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Failed: 1");
                result.StdOut.Should().Contain("\u221a TestNamespace.VSTestXunitTests.VSTestXunitPassTest");
                result.StdOut.Should().Contain("X TestNamespace.VSTestXunitTests.VSTestXunitFailTest");
            }

            result.ExitCode.Should().Be(1);
        }
        public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven()
        {
            // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests
            var    testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("5");
            string configuration        = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
            string expectedError        = Path.Combine(testProjectDirectory, "bin",
                                                       configuration, "netcoreapp3.0", "VSTestCore.dll");

            expectedError = "The test source file " + "\"" + expectedError + "\"" + " provided was not found.";

            // Call test
            CommandResult result = new DotnetTestCommand(Log)
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .Execute("--no-build", "-v:m");

            // Verify
            if (!TestContext.IsLocalized())
            {
                result.StdOut.Should().NotContain("Restore");
                //  https://github.com/dotnet/sdk/issues/3684
                //  Disable expected error check, it is sometimes giving the following error:
                //  The argument /opt/code/artifacts-ubuntu.18.04/tmp/Debug/bin/5/VSTestCore/bin/Debug/netcoreapp3.0/VSTestCore.dll is invalid. Please use the /help option to check the list of valid arguments
                //result.StdErr.Should().Contain(expectedError);
            }

            result.ExitCode.Should().Be(1);
        }
        public void ItPassesEnvironmentVariablesFromCommandLineParametersWhenRunningViaCsproj()
        {
            var testAsset = _testAssetsManager.CopyTestAsset(TestAppName)
                            .WithSource()
                            .WithVersionVariables();

            var testRoot = testAsset.Path;

            CommandResult result = new DotnetTestCommand(Log, EnvironmentVariables)
                                   .WithWorkingDirectory(testRoot)
                                   .Execute(ConsoleLoggerOutputDetailed);

            result.StdOut
            .Should().Contain(EnvironmentVariable1)
            .And.Contain(EnvironmentVariable2)
            .And.Contain(EnvironmentVariable3);

            if (!TestContext.IsLocalized())
            {
                result.StdOut
                .Should().Contain("Total tests: 1")
                .And.Contain("Passed: 1")
                .And.Contain("Passed TestEnvironmentVariables");
            }

            result.ExitCode.Should().Be(0);
        }
        public void ItTestsWithTheSpecifiedRuntimeOption()
        {
            var testInstance = TestAssets.Get("XunitCore")
                               .CreateInstance()
                               .WithSourceFiles();

            var rootPath = testInstance.Root.FullName;
            var rid      = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();

            new BuildCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput($"--runtime {rid}")
            .Should()
            .Pass()
            .And.NotHaveStdErr();

            var result = new DotnetTestCommand()
                         .WithWorkingDirectory(rootPath)
                         .ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --no-build --runtime {rid}");

            result
            .Should()
            .NotHaveStdErrContaining("MSB1001")
            .And
            .HaveStdOutContaining(rid);

            if (!DotnetUnderTest.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Failed: 1");
            }

            result.ExitCode.Should().Be(1);
        }
        public void ItCreatesMergedCoverageFileForMultiTargetedProject()
        {
            // Copy XunitMulti project in output directory of project dotnet-test.Tests
            string testAppName  = "XunitMulti";
            var    testInstance = _testAssetsManager.CopyTestAsset(testAppName, identifier: "3")
                                  .WithSource()
                                  .WithVersionVariables();

            var testProjectDirectory = testInstance.Path;

            string resultsDirectory = Path.Combine(testProjectDirectory, "RD");

            // Delete resultsDirectory if it exist
            if (Directory.Exists(resultsDirectory))
            {
                Directory.Delete(resultsDirectory, true);
            }

            // Call test
            CommandResult result = new DotnetTestCommand(Log, ConsoleLoggerOutputNormal)
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .Execute("--collect", "Code Coverage", "--results-directory", resultsDirectory);

            // Verify
            DirectoryInfo d = new DirectoryInfo(resultsDirectory);

            FileInfo[] coverageFileInfos = d.GetFiles("*.coverage", SearchOption.AllDirectories);
            Assert.Single(coverageFileInfos);
        }
        public void MStestMultiTFM()
        {
            var testProjectDirectory = _testAssetsManager.CopyTestAsset("VSTestMulti", identifier: "1")
                                       .WithSource()
                                       .WithVersionVariables()
                                       .Path;

            NuGetConfigWriter.Write(testProjectDirectory, TestContext.Current.TestPackages);

            var runtime = EnvironmentInfo.GetCompatibleRid();

            new DotnetRestoreCommand(Log, "-r", runtime)
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should().Pass();

            var result = new DotnetTestCommand(Log, "-r", runtime)
                         .WithWorkingDirectory(testProjectDirectory)
                         .Execute(ConsoleLoggerOutputNormal);

            if (!TestContext.IsLocalized())
            {
                result.StdOut
                .Should().Contain("Total tests: 3")
                .And.Contain("Passed: 2")
                .And.Contain("Failed: 1")
                .And.Contain("Passed VSTestPassTestDesktop", "because .NET 4.6 tests will pass")
                .And.Contain("Total tests: 3")
                .And.Contain("Passed: 1")
                .And.Contain("Failed: 2")
                .And.Contain("Failed VSTestFailTestNetCoreApp", "because netcoreapp2.0 tests will fail");
            }
            result.ExitCode.Should().Be(1);
        }
예제 #12
0
        public void ItBuildsAndTestsAppWhenRestoringToSpecificDirectory()
        {
            // Creating folder with name short name "RestoreTest" to avoid PathTooLongException
            var rootPath = TestAssets.Get("VSTestCore").CreateInstance("8").WithSourceFiles().Root.FullName;

            // Moving pkgs folder on top to avoid PathTooLongException
            string dir      = @"..\..\..\..\pkgs";
            string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir));

            string args = $"--packages \"{dir}\"";

            new RestoreCommand()
            .WithWorkingDirectory(rootPath)
            .Execute(args)
            .Should()
            .Pass();

            new BuildCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput()
            .Should()
            .Pass()
            .And.NotHaveStdErr();

            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(rootPath)
                                   .ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);

            result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
            result.StdOut.Should().Contain("Passed   TestNamespace.VSTestTests.VSTestPassTest");
            result.StdOut.Should().Contain("Failed   TestNamespace.VSTestTests.VSTestFailTest");
        }
예제 #13
0
        public void ItBuildsAndTestsAppWhenRestoringToSpecificDirectory()
        {
            var rootPath = TestAssets.Get("VSTestDotNetCore").CreateInstance().WithSourceFiles().Root.FullName;

            string dir      = "pkgs";
            string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir));

            string args = $"--packages \"{dir}\"";

            new RestoreCommand()
            .WithWorkingDirectory(rootPath)
            .Execute(args)
            .Should()
            .Pass();

            new BuildCommand()
            .WithWorkingDirectory(rootPath)
            .ExecuteWithCapturedOutput()
            .Should()
            .Pass()
            .And.NotHaveStdErr();

            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(rootPath)
                                   .ExecuteWithCapturedOutput();

            result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
            result.StdOut.Should().Contain("Passed   TestNamespace.VSTestTests.VSTestPassTest");
            result.StdOut.Should().Contain("Failed   TestNamespace.VSTestTests.VSTestFailTest");
        }
예제 #14
0
        public void MSTestSingleTFM()
        {
            // Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
            string testAppName  = "VSTestDotNetCore";
            var    testInstance = TestAssets.Get(testAppName)
                                  .CreateInstance()
                                  .WithSourceFiles();

            var testProjectDirectory = testInstance.Root.FullName;

            // Restore project VSTestDotNetCore
            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            // Call test
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput();

            // Verify
            result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
            result.StdOut.Should().Contain("Passed   TestNamespace.VSTestTests.VSTestPassTest");
            result.StdOut.Should().Contain("Failed   TestNamespace.VSTestTests.VSTestFailTest");
            result.ExitCode.Should().Be(1);
        }
        public void ItSetsDotnetRootToTheLocationOfDotnetExecutableWhenRunningDotnetTestWithDll()
        {
            var testAppName = "VSTestCore";
            var testAsset   = _testAssetsManager.CopyTestAsset(testAppName)
                              .WithSource()
                              .WithVersionVariables();

            var testRoot = testAsset.Path;

            var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

            new BuildCommand(testAsset)
            .Execute()
            .Should().Pass();

            var outputDll = Path.Combine(testRoot, "bin", configuration, ToolsetInfo.CurrentTargetFramework, $"{testAppName}.dll");

            // Call dotnet test + dll
            var result = new DotnetTestCommand(Log)
                         .Execute(outputDll, "--logger:console;verbosity=normal");

            result.ExitCode.Should().Be(1);
            var dotnet = result.StartInfo.FileName;

            Path.GetFileNameWithoutExtension(dotnet).Should().Be("dotnet");
            string dotnetRoot = Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)";

            result.StartInfo.EnvironmentVariables.ContainsKey(dotnetRoot).Should().BeTrue($"because {dotnetRoot} should be set");
            result.StartInfo.EnvironmentVariables[dotnetRoot].Should().Be(Path.GetDirectoryName(dotnet));
        }
        public void ItImplicitlyRestoresAProjectWhenTesting()
        {
            string testAppName  = "VSTestCore";
            var    testInstance = TestAssets.Get(testAppName)
                                  .CreateInstance()
                                  .WithSourceFiles();

            var testProjectDirectory = testInstance.Root.FullName;

            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);

            if (!DotnetUnderTest.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Total tests: 2");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Failed: 1");
                result.StdOut.Should().Contain("\u221a VSTestPassTest");
                result.StdOut.Should().Contain("X VSTestFailTest");
            }

            result.ExitCode.Should().Be(1);
        }
        public void TestsFromAGivenContainerAndArchSwitchShouldFlowToVsTestConsole()
        {
            var testAppName = "VSTestCore";
            var testAsset   = _testAssetsManager.CopyTestAsset(testAppName)
                              .WithSource()
                              .WithVersionVariables();

            var testRoot = testAsset.Path;

            var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

            new BuildCommand(testAsset)
            .Execute()
            .Should().Pass();

            var outputDll = Path.Combine(testRoot, "bin", configuration, ToolsetInfo.CurrentTargetFramework, $"{testAppName}.dll");

            // Call vstest
            var result = new DotnetTestCommand(Log)
                         .Execute(outputDll, "--arch", "wrongArchitecture");

            if (!TestContext.IsLocalized())
            {
                result.StdErr.Should().StartWith("Invalid platform type: wrongArchitecture. Valid platform types are ");
            }

            result.ExitCode.Should().Be(1);
        }
        public void GivenAProjectAndMultipleTestRunParametersItPassesThemToVStestConsoleInTheCorrectFormat()
        {
            var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("1");

            // Call test
            CommandResult result = new DotnetTestCommand(Log)
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .Execute(ConsoleLoggerOutputNormal.Concat(new[] {
                "--",
                "TestRunParameters.Parameter(name=\"myParam\",",
                "value=\"value\")",
                "TestRunParameters.Parameter(name=\"myParam2\",",
                "value=\"value",
                "with",
                "space\")"
            }));

            // Verify
            if (!TestContext.IsLocalized())
            {
                result.StdOut.Should().NotMatch("The test run parameter argument '*' is invalid.");
                result.StdOut.Should().Contain("Total tests: 1");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Passed VSTestTestRunParameters");
            }

            result.ExitCode.Should().Be(0);
        }
        public void ItAcceptsMultipleLoggersAsCliArguments()
        {
            // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests
            var    testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("10");
            var    trxFileNamePattern   = "custom*.trx";
            string trxLoggerDirectory   = Path.Combine(testProjectDirectory, "RD");

            // Delete trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }

            // Call test with logger enable
            CommandResult result = new DotnetTestCommand(Log)
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .Execute("--logger", "trx;logfilename=custom.trx", "--logger",
                                            "console;verbosity=normal", "--", "RunConfiguration.ResultsDirectory=" + trxLoggerDirectory);

            // Verify
            if (!TestContext.IsLocalized())
            {
                // We append current date time to trx file name, hence modifying this check
                Assert.True(Directory.EnumerateFiles(trxLoggerDirectory, trxFileNamePattern).Any());

                result.StdOut.Should().Contain("\u221a VSTestPassTest");
                result.StdOut.Should().Contain("X VSTestFailTest");
            }

            // Cleanup trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }
        }
예제 #20
0
        public void MStestMultiTFM()
        {
            var testProjectDirectory = TestAssets.Get("VSTestDesktopAndNetCore")
                                       .CreateInstance()
                                       .WithSourceFiles()
                                       .WithNuGetConfig(new RepoDirectoriesProvider().TestPackages)
                                       .Root;

            var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();

            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .WithRuntime(runtime)
            .Execute()
            .Should().Pass();

            var result = new DotnetTestCommand()
                         .WithWorkingDirectory(testProjectDirectory)
                         .WithRuntime(runtime)
                         .ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);

            result.StdOut
            .Should().Contain("Total tests: 3. Passed: 2. Failed: 1. Skipped: 0.", "because .NET 4.6 tests will pass")
            .And.Contain("Passed   TestNamespace.VSTestTests.VSTestPassTestDesktop", "because .NET 4.6 tests will pass")
            .And.Contain("Total tests: 3. Passed: 1. Failed: 2. Skipped: 0.", "because netcoreapp2.0 tests will fail")
            .And.Contain("Failed   TestNamespace.VSTestTests.VSTestFailTestNetCoreApp", "because netcoreapp2.0 tests will fail");
            result.ExitCode.Should().Be(1);
        }
        public void ItCreatesTrxReportInTheSpecifiedResultsDirectoryByArgs()
        {
            // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests
            var    testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("7");
            var    trxFileNamePattern   = "custom*.trx";
            string trxLoggerDirectory   = Path.Combine(testProjectDirectory, "RD");

            // Delete trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }

            // Call test with logger enable
            CommandResult result = new DotnetTestCommand(Log)
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .Execute("--logger", "trx;logfilename=custom.trx", "--",
                                            "RunConfiguration.ResultsDirectory=" + trxLoggerDirectory);

            // Verify
            // We append current date time to trx file name, hence modifying this check
            Assert.True(Directory.EnumerateFiles(trxLoggerDirectory, trxFileNamePattern).Any());

            // Cleanup trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }
        }
예제 #22
0
        public void XunitMultiTFM()
        {
            // Copy VSTestXunitDesktopAndNetCore project in output directory of project dotnet-test.Tests
            string testAppName  = "VSTestXunitDesktopAndNetCore";
            var    testInstance = TestAssets.Get(testAppName)
                                  .CreateInstance()
                                  .WithSourceFiles();

            var testProjectDirectory = testInstance.Root.FullName;

            // Restore project VSTestXunitDesktopAndNetCore
            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            // Call test
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);

            // Verify
            // for target framework net46
            result.StdOut.Should().Contain("Total tests: 3. Passed: 2. Failed: 1. Skipped: 0.");
            result.StdOut.Should().Contain("Passed   TestNamespace.VSTestXunitTests.VSTestXunitPassTestDesktop");

            // for target framework netcoreapp1.0
            result.StdOut.Should().Contain("Total tests: 3. Passed: 1. Failed: 2. Skipped: 0.");
            result.StdOut.Should().Contain("Failed   TestNamespace.VSTestXunitTests.VSTestXunitFailTestNetCoreApp");
            result.ExitCode.Should().Be(1);
        }
        public void ItCreatesCoverageFileInResultsDirectory()
        {
            var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("12");

            string resultsDirectory = Path.Combine(testProjectDirectory, "RD");

            // Delete resultsDirectory if it exist
            if (Directory.Exists(resultsDirectory))
            {
                Directory.Delete(resultsDirectory, true);
            }

            // Call test
            CommandResult result = new DotnetTestCommand(Log)
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .Execute(
                "--collect", "Code Coverage",
                "--results-directory", resultsDirectory);

            // Verify test results
            if (!TestContext.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2");
                result.StdOut.Should().Contain("Passed: 1");
                result.StdOut.Should().Contain("Failed: 1");
            }

            // Verify coverage file.
            DirectoryInfo d = new DirectoryInfo(resultsDirectory);

            FileInfo[] coverageFileInfos = d.GetFiles("*.coverage", SearchOption.AllDirectories);
            Assert.Single(coverageFileInfos);

            result.ExitCode.Should().Be(1);
        }
        public void ItAcceptsMultipleLoggersAsCliArguments()
        {
            // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests
            var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("10");

            string trxLoggerDirectory = Path.Combine(testProjectDirectory, "RD");

            // Delete trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }

            // Call test with logger enable
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput("--logger \"trx;logfilename=custom.trx\" --logger console;verbosity=normal -- RunConfiguration.ResultsDirectory=" + trxLoggerDirectory);

            // Verify
            var trxFilePath = Path.Combine(trxLoggerDirectory, "custom.trx");

            Assert.True(File.Exists(trxFilePath));
            result.StdOut.Should().Contain(trxFilePath);
            result.StdOut.Should().Contain("Passed   VSTestPassTest");
            result.StdOut.Should().Contain("Failed   VSTestFailTest");

            // Cleanup trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }
        }
        public void XunitSingleTFM()
        {
            // Copy VSTestXunitDotNetCore project in output directory of project dotnet-vstest.Tests
            string       testAppName  = "VSTestXunitDotNetCore";
            TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);

            string testProjectDirectory = testInstance.TestRoot;

            // Restore project VSTestXunitDotNetCore
            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            // Call test
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput();

            // Verify
            result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
            result.StdOut.Should().Contain("Passed   TestNamespace.VSTestXunitTests.VSTestXunitPassTest");
            result.StdOut.Should().Contain("Failed   TestNamespace.VSTestXunitTests.VSTestXunitFailTest");
        }
        public void ItCreatesCoverageFileInResultsDirectory()
        {
            var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("12");

            string resultsDirectory = Path.Combine(testProjectDirectory, "RD");

            // Delete resultsDirectory if it exist
            if (Directory.Exists(resultsDirectory))
            {
                Directory.Delete(resultsDirectory, true);
            }

            // Call test
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput(
                "--collect \"Code Coverage\" "
                + "--results-directory " + resultsDirectory);

            // Verify test results
            if (!DotnetUnderTest.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
            }

            // Verify coverage file.
            DirectoryInfo d = new DirectoryInfo(resultsDirectory);

            FileInfo[] coverageFileInfos = d.GetFiles("*.coverage", SearchOption.AllDirectories);
            Assert.Equal(1, coverageFileInfos.Length);

            result.ExitCode.Should().Be(1);
        }
예제 #27
0
        public void TestWillCreateTrxLoggerInTheSpecifiedResultsDirectoryBySwitch()
        {
            // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests
            var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("6");

            string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TR", "x.y");

            // Delete trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }

            // Call test with trx logger enabled and results directory explicitly specified.
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput("--logger trx -r \"" + trxLoggerDirectory + "\"");

            // Verify
            String[] trxFiles = Directory.GetFiles(trxLoggerDirectory, "*.trx");
            Assert.Equal(1, trxFiles.Length);
            result.StdOut.Should().Contain(trxFiles[0]);

            // Cleanup trxLoggerDirectory if it exist
            if (Directory.Exists(trxLoggerDirectory))
            {
                Directory.Delete(trxLoggerDirectory, true);
            }
        }
        public void TestsFromAGivenContainerShouldRunWithExpectedOutput()
        {
            var testAppName = "VSTestCore";
            var testAsset   = _testAssetsManager.CopyTestAsset(testAppName)
                              .WithSource()
                              .WithVersionVariables();

            var testRoot = testAsset.Path;

            var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

            new BuildCommand(testAsset)
            .Execute()
            .Should().Pass();

            var outputDll = Path.Combine(testRoot, "bin", configuration, ToolsetInfo.CurrentTargetFramework, $"{testAppName}.dll");

            // Call vstest
            var result = new DotnetTestCommand(Log)
                         .Execute(outputDll, "--logger:console;verbosity=normal");

            if (!TestContext.IsLocalized())
            {
                result.StdOut
                .Should().Contain("Total tests: 2")
                .And.Contain("Passed: 1")
                .And.Contain("Failed: 1")
                .And.Contain("Passed VSTestPassTest")
                .And.Contain("Failed VSTestFailTest");
            }

            result.ExitCode.Should().Be(1);
        }
예제 #29
0
        public void XunitSingleTFM()
        {
            // Copy XunitCore project in output directory of project dotnet-vstest.Tests
            string testAppName  = "XunitCore";
            var    testInstance = TestAssets.Get(testAppName)
                                  .CreateInstance("4")
                                  .WithSourceFiles();

            var testProjectDirectory = testInstance.Root.FullName;

            // Restore project XunitCore
            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            // Call test
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal);

            // Verify
            if (!DotnetUnderTest.IsLocalized())
            {
                result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
                result.StdOut.Should().Contain("Passed   TestNamespace.VSTestXunitTests.VSTestXunitPassTest");
                result.StdOut.Should().Contain("Failed   TestNamespace.VSTestXunitTests.VSTestXunitFailTest");
            }

            result.ExitCode.Should().Be(1);
        }
예제 #30
0
        public void TestsFromAGivenProjectShouldRunWithExpectedOutput()
        {
            // Copy DotNetCoreTestProject project in output directory of project dotnet-vstest.Tests
            string       testAppName  = "VSTestDotNetCoreProject";
            TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);

            string testProjectDirectory = testInstance.TestRoot;

            // Restore project VSTestDotNetCoreProject
            new RestoreCommand()
            .WithWorkingDirectory(testProjectDirectory)
            .Execute()
            .Should()
            .Pass();

            // Call test
            CommandResult result = new DotnetTestCommand()
                                   .WithWorkingDirectory(testProjectDirectory)
                                   .ExecuteWithCapturedOutput("/p:TargetFramework=netcoreapp1.0");

            // Verify
            result.StdOut.Should().Contain("Total tests: 2. Passed: 1. Failed: 1. Skipped: 0.");
            result.StdOut.Should().Contain("Passed   TestNamespace.VSTestTests.VSTestPassTest");
            result.StdOut.Should().Contain("Failed   TestNamespace.VSTestTests.VSTestFailTest");
        }