From 3dd3e16d789bd6f1e8d87004c0ba9db95e331be0 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 27 Aug 2025 05:47:25 +0200 Subject: [PATCH 1/2] _MTPBuild should only build if MTP project --- .../ImportAfter/Microsoft.TestPlatform.ImportAfter.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Layout/redist/MSBuildImports/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets b/src/Layout/redist/MSBuildImports/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets index 2685099bb450..bf368fc72775 100644 --- a/src/Layout/redist/MSBuildImports/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets +++ b/src/Layout/redist/MSBuildImports/Current/Microsoft.Common.targets/ImportAfter/Microsoft.TestPlatform.ImportAfter.targets @@ -18,6 +18,6 @@ Copyright (c) .NET Foundation. All rights reserved. - + From 80e192b2187ed5c7d8ad9dc70707dc1c12470354 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 27 Aug 2025 07:30:11 +0200 Subject: [PATCH 2/2] Add test --- .../ClassLibrary/Class1.cs | 6 +++ .../ClassLibrary/ClassLibrary.csproj | 7 +++ .../TestProject/Program.cs | 46 +++++++++++++++++++ .../TestProject/TestProject.csproj | 19 ++++++++ ...stProjectWithClassLibraryDifferentTFMs.sln | 31 +++++++++++++ .../dotnet.config | 2 + .../Test/GivenDotnetTestBuildsAndRunsTests.cs | 16 +++++-- 7 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/ClassLibrary/Class1.cs create mode 100644 test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/ClassLibrary/ClassLibrary.csproj create mode 100644 test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProject/Program.cs create mode 100644 test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProject/TestProject.csproj create mode 100644 test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProjectWithClassLibraryDifferentTFMs.sln create mode 100644 test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/dotnet.config diff --git a/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/ClassLibrary/Class1.cs b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/ClassLibrary/Class1.cs new file mode 100644 index 000000000000..534e4f348652 --- /dev/null +++ b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/ClassLibrary/Class1.cs @@ -0,0 +1,6 @@ +namespace ClassLibrary +{ + public class Class1 + { + } +} diff --git a/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/ClassLibrary/ClassLibrary.csproj b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/ClassLibrary/ClassLibrary.csproj new file mode 100644 index 000000000000..dbdcea46b6e2 --- /dev/null +++ b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/ClassLibrary/ClassLibrary.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProject/Program.cs b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProject/Program.cs new file mode 100644 index 000000000000..28a9001705af --- /dev/null +++ b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProject/Program.cs @@ -0,0 +1,46 @@ +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions.Messages; +using Microsoft.Testing.Platform.Extensions.TestFramework; + +var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args); + +testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, __) => new DummyTestAdapter()); + +using var testApplication = await testApplicationBuilder.BuildAsync(); +return await testApplication.RunAsync(); + +public class DummyTestAdapter : ITestFramework, IDataProducer +{ + public string Uid => nameof(DummyTestAdapter); + + public string Version => "2.0.0"; + + public string DisplayName => nameof(DummyTestAdapter); + + public string Description => nameof(DummyTestAdapter); + + public Task IsEnabledAsync() => Task.FromResult(true); + + public Type[] DataTypesProduced => new[] { + typeof(TestNodeUpdateMessage) + }; + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + + public async Task ExecuteRequestAsync(ExecuteRequestContext context) + { + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode() + { + Uid = "Test0", + DisplayName = "Test0", + Properties = new PropertyBag(new PassedTestNodeStateProperty("OK")), + })); + + context.Complete(); + } +} \ No newline at end of file diff --git a/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProject/TestProject.csproj b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProject/TestProject.csproj new file mode 100644 index 000000000000..090a18debb4c --- /dev/null +++ b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProject/TestProject.csproj @@ -0,0 +1,19 @@ + + + + + Exe + $(CurrentTargetFramework) + enable + enable + + + + + + + + + + + diff --git a/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProjectWithClassLibraryDifferentTFMs.sln b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProjectWithClassLibraryDifferentTFMs.sln new file mode 100644 index 000000000000..c042974108d5 --- /dev/null +++ b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/TestProjectWithClassLibraryDifferentTFMs.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.35712.36 main +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TestProject\TestProject.csproj", "{4868FD55-C56D-445C-9F83-A063302EC78F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary", "ClassLibrary\ClassLibrary.csproj", "{729A12AB-4D79-4756-A776-C7BB63D30A4F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4868FD55-C56D-445C-9F83-A063302EC78F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4868FD55-C56D-445C-9F83-A063302EC78F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4868FD55-C56D-445C-9F83-A063302EC78F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4868FD55-C56D-445C-9F83-A063302EC78F}.Release|Any CPU.Build.0 = Release|Any CPU + {729A12AB-4D79-4756-A776-C7BB63D30A4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {729A12AB-4D79-4756-A776-C7BB63D30A4F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {729A12AB-4D79-4756-A776-C7BB63D30A4F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {729A12AB-4D79-4756-A776-C7BB63D30A4F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E2F590CA-47E0-4145-924B-3E398540BA45} + EndGlobalSection +EndGlobal diff --git a/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/dotnet.config b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/dotnet.config new file mode 100644 index 000000000000..28daa0a28213 --- /dev/null +++ b/test/TestAssets/TestProjects/TestProjectWithClassLibraryDifferentTFMs/dotnet.config @@ -0,0 +1,2 @@ +[dotnet.test.runner] +name= "Microsoft.Testing.Platform" \ No newline at end of file diff --git a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs index 059d1ea06800..a238c2ac8184 100644 --- a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs +++ b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs @@ -345,17 +345,23 @@ public void RunOnProjectWithSolutionFile_ShouldReturnExitCodeGenericFailure(stri result.ExitCode.Should().Be(ExitCodes.GenericFailure); } - [InlineData(TestingConstants.Debug)] - [InlineData(TestingConstants.Release)] [Theory] - public void RunOnProjectWithClassLibrary_ShouldReturnExitCodeSuccess(string configuration) + [CombinatorialData] + public void RunOnProjectWithClassLibrary_ShouldReturnExitCodeSuccess( + [CombinatorialValues(TestingConstants.Debug, TestingConstants.Release)] string configuration, + [CombinatorialValues("TestProjectWithClassLibrary", "TestProjectWithClassLibraryDifferentTFMs")] string assetName, + bool useFrameworkOption) { - TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectWithClassLibrary", Guid.NewGuid().ToString()) + TestAsset testInstance = _testAssetsManager.CopyTestAsset(assetName, Guid.NewGuid().ToString()) .WithSource(); + string[] args = useFrameworkOption + ? new[] { TestingPlatformOptions.ConfigurationOption.Name, configuration, TestingPlatformOptions.FrameworkOption.Name, ToolsetInfo.CurrentTargetFramework } + : new[] { TestingPlatformOptions.ConfigurationOption.Name, configuration }; + CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false) .WithWorkingDirectory(testInstance.Path) - .Execute(TestingPlatformOptions.ConfigurationOption.Name, configuration); + .Execute(args); if (!TestContext.IsLocalized()) {