From 5b6362f29afe2e1aeee3f8a9f4d84f4d6e56fdb9 Mon Sep 17 00:00:00 2001 From: Brennan Date: Wed, 7 Oct 2020 14:37:33 -0700 Subject: [PATCH] Enable test logging for ProjectTemplate tests (#26507) * Enable test logging for ProjectTemplate tests * Add logging to templates * some updates * nullref --- .../AssemblyInfo.AssemblyFixtures.cs | 2 +- ...soft.AspNetCore.Components.E2ETests.csproj | 2 - .../AssemblyInfo.AssemblyFixtures.cs | 8 +- .../BlazorTemplates.Tests.csproj | 13 +- .../Shared/ProjectFactoryFixture.cs | 2 +- .../Shared/TestOutputLogger.cs | 28 +++++ .../test/AssemblyInfo.AssemblyFixtures.cs | 7 +- src/ProjectTemplates/test/BaselineTest.cs | 18 ++- .../test/ByteOrderMarkTest.cs | 28 +++-- .../test/EmptyWebTemplateTest.cs | 42 ++++--- src/ProjectTemplates/test/GrpcTemplateTest.cs | 56 ++++----- .../test/IdentityUIPackageTest.cs | 50 ++++---- src/ProjectTemplates/test/MvcTemplateTest.cs | 114 ++++++++++-------- .../test/ProjectTemplates.Tests.csproj | 8 +- .../test/RazorClassLibraryTemplateTest.cs | 48 +++++--- .../test/RazorPagesTemplateTest.cs | 98 ++++++++------- .../test/WebApiTemplateTest.cs | 64 +++++----- .../test/WorkerTemplateTest.cs | 41 ++++--- .../AssemblyFixtureAttribute.cs | 17 --- ...TestCollectionRunnerWIthAssemblyFixture.cs | 48 -------- ...itTestAssemblyRunnerWithAssemblyFixture.cs | 82 ------------- ...estFrameworkExecutorWithAssemblyFixture.cs | 26 ---- .../XunitTestFrameworkWithAssemblyFixture.cs | 20 --- 23 files changed, 361 insertions(+), 461 deletions(-) create mode 100644 src/ProjectTemplates/Shared/TestOutputLogger.cs delete mode 100644 src/Shared/E2ETesting/XUnitExtensions/AssemblyFixtureAttribute.cs delete mode 100644 src/Shared/E2ETesting/XUnitExtensions/XUnitTestCollectionRunnerWIthAssemblyFixture.cs delete mode 100644 src/Shared/E2ETesting/XUnitExtensions/XunitTestAssemblyRunnerWithAssemblyFixture.cs delete mode 100644 src/Shared/E2ETesting/XUnitExtensions/XunitTestFrameworkExecutorWithAssemblyFixture.cs delete mode 100644 src/Shared/E2ETesting/XUnitExtensions/XunitTestFrameworkWithAssemblyFixture.cs diff --git a/src/Components/test/E2ETest/Infrastructure/AssemblyInfo.AssemblyFixtures.cs b/src/Components/test/E2ETest/Infrastructure/AssemblyInfo.AssemblyFixtures.cs index 4f2868269a..d7e5921fef 100644 --- a/src/Components/test/E2ETest/Infrastructure/AssemblyInfo.AssemblyFixtures.cs +++ b/src/Components/test/E2ETest/Infrastructure/AssemblyInfo.AssemblyFixtures.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.E2ETesting; +using Microsoft.AspNetCore.Testing; using Xunit; -[assembly: TestFramework("Microsoft.AspNetCore.E2ETesting.XunitTestFrameworkWithAssemblyFixture", "Microsoft.AspNetCore.Components.E2ETests")] [assembly: AssemblyFixture(typeof(SeleniumStandaloneServer))] [assembly: AssemblyFixture(typeof(SauceConnectServer))] diff --git a/src/Components/test/E2ETest/Microsoft.AspNetCore.Components.E2ETests.csproj b/src/Components/test/E2ETest/Microsoft.AspNetCore.Components.E2ETests.csproj index 266bd5d4fc..c727765672 100644 --- a/src/Components/test/E2ETest/Microsoft.AspNetCore.Components.E2ETests.csproj +++ b/src/Components/test/E2ETest/Microsoft.AspNetCore.Components.E2ETests.csproj @@ -19,8 +19,6 @@ - false - false diff --git a/src/ProjectTemplates/BlazorTemplates.Tests/AssemblyInfo.AssemblyFixtures.cs b/src/ProjectTemplates/BlazorTemplates.Tests/AssemblyInfo.AssemblyFixtures.cs index 57f163b513..b60a694a12 100644 --- a/src/ProjectTemplates/BlazorTemplates.Tests/AssemblyInfo.AssemblyFixtures.cs +++ b/src/ProjectTemplates/BlazorTemplates.Tests/AssemblyInfo.AssemblyFixtures.cs @@ -2,11 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.E2ETesting; +using Microsoft.AspNetCore.Testing; using Templates.Test.Helpers; -using Xunit; -[assembly: TestFramework("Microsoft.AspNetCore.E2ETesting.XunitTestFrameworkWithAssemblyFixture", "BlazorTemplates.Tests")] - -[assembly: Microsoft.AspNetCore.E2ETesting.AssemblyFixture(typeof(ProjectFactoryFixture))] -[assembly: Microsoft.AspNetCore.E2ETesting.AssemblyFixture(typeof(SeleniumStandaloneServer))] +[assembly: AssemblyFixture(typeof(ProjectFactoryFixture))] +[assembly: AssemblyFixture(typeof(SeleniumStandaloneServer))] diff --git a/src/ProjectTemplates/BlazorTemplates.Tests/BlazorTemplates.Tests.csproj b/src/ProjectTemplates/BlazorTemplates.Tests/BlazorTemplates.Tests.csproj index 2da0e11666..ba179c77d0 100644 --- a/src/ProjectTemplates/BlazorTemplates.Tests/BlazorTemplates.Tests.csproj +++ b/src/ProjectTemplates/BlazorTemplates.Tests/BlazorTemplates.Tests.csproj @@ -1,4 +1,4 @@ - + @@ -22,7 +22,6 @@ TestTemplates\ $([MSBuild]::EnsureTrailingSlash('$(RepoRoot)'))obj\template-restore\ TemplateTests.props - false true @@ -43,11 +42,6 @@ - - true - false - - <_Parameter1>DotNetEfFullPath @@ -65,11 +59,6 @@ <_Parameter1>ContinuousIntegrationBuild <_Parameter2>true - - <_Parameter1>$(PreserveExistingLogsInOutput) - <_Parameter2>$(TargetFramework) - <_Parameter3> - diff --git a/src/ProjectTemplates/Shared/ProjectFactoryFixture.cs b/src/ProjectTemplates/Shared/ProjectFactoryFixture.cs index d268ce8742..46763a3b96 100644 --- a/src/ProjectTemplates/Shared/ProjectFactoryFixture.cs +++ b/src/ProjectTemplates/Shared/ProjectFactoryFixture.cs @@ -55,7 +55,7 @@ namespace Templates.Test.Helpers } private static string GetTemplateFolderBasePath(Assembly assembly) => - (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HELIX_DIR"))) + (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HELIX_DIR"))) ? assembly.GetCustomAttributes() .Single(a => a.Key == "TestTemplateCreationFolder") .Value diff --git a/src/ProjectTemplates/Shared/TestOutputLogger.cs b/src/ProjectTemplates/Shared/TestOutputLogger.cs new file mode 100644 index 0000000000..b01edf2e7b --- /dev/null +++ b/src/ProjectTemplates/Shared/TestOutputLogger.cs @@ -0,0 +1,28 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.Extensions.Logging; +using Xunit.Abstractions; + +namespace Templates.Test.Helpers +{ + internal class TestOutputLogger : ITestOutputHelper + { + private readonly ILogger _logger; + + public TestOutputLogger(ILogger logger) + { + _logger = logger; + } + + public void WriteLine(string message) + { + _logger.LogInformation(message); + } + + public void WriteLine(string format, params object[] args) + { + _logger.LogInformation(string.Format(format, args)); + } + } +} diff --git a/src/ProjectTemplates/test/AssemblyInfo.AssemblyFixtures.cs b/src/ProjectTemplates/test/AssemblyInfo.AssemblyFixtures.cs index 9e4d5d6b34..dded12fce8 100644 --- a/src/ProjectTemplates/test/AssemblyInfo.AssemblyFixtures.cs +++ b/src/ProjectTemplates/test/AssemblyInfo.AssemblyFixtures.cs @@ -4,9 +4,6 @@ using Microsoft.AspNetCore.E2ETesting; using Microsoft.AspNetCore.Testing; using Templates.Test.Helpers; -using Xunit; -[assembly: TestFramework("Microsoft.AspNetCore.E2ETesting.XunitTestFrameworkWithAssemblyFixture", "ProjectTemplates.Tests")] - -[assembly: Microsoft.AspNetCore.E2ETesting.AssemblyFixture(typeof(ProjectFactoryFixture))] -[assembly: Microsoft.AspNetCore.E2ETesting.AssemblyFixture(typeof(SeleniumStandaloneServer))] +[assembly: AssemblyFixture(typeof(ProjectFactoryFixture))] +[assembly: AssemblyFixture(typeof(SeleniumStandaloneServer))] diff --git a/src/ProjectTemplates/test/BaselineTest.cs b/src/ProjectTemplates/test/BaselineTest.cs index eabacc336d..23e9320ec7 100644 --- a/src/ProjectTemplates/test/BaselineTest.cs +++ b/src/ProjectTemplates/test/BaselineTest.cs @@ -15,7 +15,7 @@ using Xunit.Abstractions; namespace Templates.Test { - public class BaselineTest + public class BaselineTest : LoggedTest { private static readonly Regex TemplateNameRegex = new Regex( "new (?