-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathDotnetTestMSBuildOutputTests.cs
More file actions
84 lines (69 loc) · 4.61 KB
/
DotnetTestMSBuildOutputTests.cs
File metadata and controls
84 lines (69 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.TestPlatform.AcceptanceTests;
/// <summary>
/// Running dotnet test + csproj and using MSBuild for the output.
/// </summary>
[TestClass]
[SkipIOutOfProcessTestOnNetFrameworkCondition]
public class DotnetTestMSBuildOutputTests : AcceptanceTestBase
{
[TestMethod]
// patched dotnet is not published on non-windows systems
[TestCategory("Windows-Review")]
[NetCoreTargetFrameworkDataSource(useDesktopRunner: false)]
public void MSBuildLoggerCanBeEnabledByBuildPropertyAndDoesNotEatSpecialChars(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj");
// Forcing terminal logger so we can see the output when it is redirected
InvokeDotnetTest($@"{projectPath} --no-build -tl:on", workingDirectory: Path.GetDirectoryName(projectPath));
// The output:
// Determining projects to restore...
// Restored C:\Users\nohwnd\AppData\Local\Temp\vstest\xvoVt\SimpleTestProject.csproj (in 441 ms).
// SimpleTestProject -> C:\Users\nohwnd\AppData\Local\Temp\vstest\xvoVt\artifacts\bin\TestAssets\SimpleTestProject\Debug\net462\SimpleTestProject.dll
// SimpleTestProject -> C:\Users\nohwnd\AppData\Local\Temp\vstest\xvoVt\artifacts\bin\TestAssets\SimpleTestProject\Debug\net8.0\SimpleTestProject.dll
// C:\Users\nohwnd\AppData\Local\Temp\vstest\xvoVt\UnitTest1.cs(41): error VSTEST1: (FailingTest) SampleUnitTestProject.UnitTest1.FailingTest() Assert.AreEqual failed. Expected:<2>. Actual:<3>. [C:\Users\nohwnd\AppData\Local\Temp\vstest\xvoVt\SimpleTestProject.csproj::TargetFramework=net462]
// C:\Users\nohwnd\AppData\Local\Temp\vstest\xvoVt\UnitTest1.cs(41): error VSTEST1: (FailingTest) SampleUnitTestProject.UnitTest1.FailingTest() Assert.AreEqual failed. Expected:<2>. Actual:<3>. [C:\Users\nohwnd\AppData\Local\Temp\vstest\xvoVt\SimpleTestProject.csproj::TargetFramework=net8.0]
StdOutputContains("TESTERROR");
StdOutputContains("FailingTest (");
StdOutputContains("Expected: \"ğğğ𦮙我們剛才從𓋴𓅓𓏏𓇏𓇌𓀀\"");
StdOutputContains("at TerminalLoggerUnitTests.UnitTest1.FailingTest() in");
// We are sending those as low prio messages, they won't show up on screen but will be in binlog.
//StdOutputContains("passed PassingTest");
//StdOutputContains("skipped SkippingTest");
ExitCodeEquals(1);
}
[TestMethod]
// patched dotnet is not published on non-windows systems
[TestCategory("Windows-Review")]
[NetCoreTargetFrameworkDataSource(useDesktopRunner: false)]
public void MSBuildLoggerCanBeDisabledByBuildProperty(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj");
InvokeDotnetTest($@"{projectPath} --no-build -nodereuse:false /p:VsTestUseMSBuildOutput=false", workingDirectory: Path.GetDirectoryName(projectPath));
// Check that we see the summary that is printed from the console logger, meaning the new output is disabled.
StdOutputContains("Failed! - Failed: 1, Passed: 1, Skipped: 1, Total: 3, Duration:");
// We are sending those as low prio messages, they won't show up on screen but will be in binlog.
//StdOutputContains("passed PassingTest");
//StdOutputContains("skipped SkippingTest");
ExitCodeEquals(1);
}
[TestMethod]
// patched dotnet is not published on non-windows systems
[TestCategory("Windows-Review")]
[NetCoreTargetFrameworkDataSource(useDesktopRunner: false)]
public void MSBuildLoggerCanBeDisabledByEnvironmentVariableProperty(RunnerInfo runnerInfo)
{
SetTestEnvironment(_testEnvironment, runnerInfo);
var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj");
InvokeDotnetTest($@"{projectPath} --no-build -nodereuse:false", environmentVariables: new Dictionary<string, string?> { ["MSBUILDENSURESTDOUTFORTASKPROCESSES"] = "1" }, workingDirectory: Path.GetDirectoryName(projectPath));
// Check that we see the summary that is printed from the console logger, meaning the new output is disabled.
StdOutputContains("Failed! - Failed: 1, Passed: 1, Skipped: 1, Total: 3, Duration:");
ExitCodeEquals(1);
}
}