Skip to content

Commit bd78255

Browse files
Update logic of mixed mode of dotnet test (#47407)
1 parent 6e5da92 commit bd78255

15 files changed

+100
-40
lines changed

src/Cli/dotnet/commands/dotnet-test/LocalizableStrings.resx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ For MSTest before 2.2.4, the timeout is used for all testcases.</value>
317317
<comment>{0} - test message state</comment>
318318
</data>
319319
<data name="CmdUnsupportedVSTestTestApplicationsDescription" xml:space="preserve">
320-
<value>Test project '{0}' is using VSTest. When opting-in via dotnet.config, all the test projects are expected to be using Microsoft.Testing.Platform.
320+
<value>When opting-in via dotnet.config, all test projects are expected to be using Microsoft.Testing.Platform.
321+
The following test projects are using VSTest:
322+
{0}
321323
See https://aka.ms/dotnet-test/mtp for more information.</value>
322324
</data>
323325
<data name="Aborted" xml:space="preserve">

src/Cli/dotnet/commands/dotnet-test/MSBuildHandler.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
54
using System.Collections.Concurrent;
6-
using System.IO;
5+
using System.Diagnostics;
76
using Microsoft.DotNet.Tools.Common;
87
using Microsoft.DotNet.Tools.Test;
98
using Microsoft.Testing.Platform.OutputDevice;
@@ -91,21 +90,28 @@ private int RunBuild(string filePath, bool isSolution, BuildOptions buildOptions
9190

9291
private void InitializeTestApplications(IEnumerable<TestModule> modules)
9392
{
93+
// If one test app has IsTestingPlatformApplication set to false (VSTest and not MTP), then we will not run any of the test apps
94+
IEnumerable<TestModule> vsTestTestProjects = modules.Where(module => !module.IsTestingPlatformApplication);
95+
96+
if (vsTestTestProjects.Any())
97+
{
98+
_areTestingPlatformApplications = false;
99+
100+
_output.WriteMessage(
101+
string.Format(
102+
LocalizableStrings.CmdUnsupportedVSTestTestApplicationsDescription,
103+
string.Join(Environment.NewLine, vsTestTestProjects.Select(module => Path.GetFileName(module.ProjectFullPath)))),
104+
new SystemConsoleColor { ConsoleColor = ConsoleColor.Red });
105+
106+
return;
107+
}
108+
94109
foreach (TestModule module in modules)
95110
{
96111
if (!module.IsTestProject && !module.IsTestingPlatformApplication)
97112
{
98-
// This should never happen. We should only ever create Module if it's a test project.
99-
throw new InvalidOperationException();
100-
}
101-
102-
if (!module.IsTestingPlatformApplication)
103-
{
104-
// If one test app has IsTestingPlatformApplication set to false (VSTest and not MTP), then we will not run any of the test apps
105-
// Note that we still continue the loop here so that we print all projects that are VSTest and not MTP.
106-
_areTestingPlatformApplications = false;
107-
_output.WriteMessage(string.Format(LocalizableStrings.CmdUnsupportedVSTestTestApplicationsDescription, Path.GetFileName(module.ProjectFullPath)), new SystemConsoleColor { ConsoleColor = ConsoleColor.Red });
108-
continue;
113+
// This should never happen. We should only ever create TestModule if it's a test project.
114+
throw new UnreachableException($"This program location is thought to be unreachable. Class='{nameof(MSBuildHandler)}' Method='{nameof(InitializeTestApplications)}'");
109115
}
110116

111117
var testApp = new TestApplication(module, _args);

src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.cs.xlf

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.de.xlf

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.es.xlf

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.fr.xlf

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.it.xlf

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ja.xlf

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.ko.xlf

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Cli/dotnet/commands/dotnet-test/xlf/LocalizableStrings.pl.xlf

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)