Skip to content

Testing.Platform should not be a blackbox: leveraging standard Hosting model and Program.cs for test application setup #4198

@julealgon

Description

@julealgon

Summary

I've started playing around with the new platform and I'm disappointed in how cryptic and "magical" everything is. Everything is either controlled by random and super undiscoverable MSBuild properties or worse, through environment variables.

With modern applications, the C# ecosystem has shifted from cryptic project-based settings and configuration files, to a much more visible and flexible Program.cs-based C# setup for libraries, settings etc, and this new Testing.Platform should tap into that.

Background and Motivation

The way Testing.Platform works today is just... cryptic, and not idiomatic C# compared to other types of applications. Things are not discoverable, and the way they are setup is through nonstandard means such as csproj flags.

I also want to be able to leverage common patterns and practices that I already leverage in other project types, such as proper dependency injection support, I want to add OpenTelemetry to my tests to monitor their execution in Datadog, I want to add tests from different projects and combine them in a single host, I want to be able to configure details of my tests using our company-wide Azure AppConfiguration instance.

Proposed Feature

I propose that all test projects using the new Testing.Platform have their Program.cs files fully exposed and NOT autogenerated based on .csproj settings. All (or most of at least) MSBuild properties should be deprecated in favor of explicit configuration properties that the developer can set as part of some AddTestingPlatform or UseTestingPlatform call in their Program.cs files, like other types of applications do today.

These methods would be integrated via a new TestApplication.CreateBuilder(args) method that is the entry point to the hosting model used by every other modern application, including ASP.NET (WebApplication.CreateBuilder(args);), Worker projects (Host.CreateApplicationBuilder(args)), Azure Functions (FunctionsApplication.CreateBuilder(args)), etc.

This would then automatically bring first-class support for:

  • logging
  • metrics
  • dependency injection
  • configuration

For test projects.

All extension points provided by Testing.Platform would then be DI-friendly, and the hooks would be exposed and configurable in Program.cs, again like any other standard application.

Need to add MSTest support? Add the MSTest nuget package, then call AddMSTest(Action<MSTestOptions>) or some similar method (instead of flipping some weird MSBuild variable. Same for any other test engine.

Need to disable platform telemetry? Set some Option property to false, or bind it to a configuration file or to Azure AppConfig where you set it to false, instead of.... setting an environment variable:

To disable telemetry, set either TESTINGPLATFORM_TELEMETRY_OPTOUT or DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1.

If this is standardized enough, I could even setup some tests to run as part of my ASP.NET Core API, or I could setup a windows service that runs tests, the same way I can host an API in a windows service today because each of these "aspects" is modular and independent enough and can be combined. The same way I can add ASPNET.Core capabilities to my Azure Function isolated function and have it use common ASP.NET types for HTTP.

Alternative Designs

None. I think any alternative to the above deviates from how modern projects are written and should be avoided.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: MTPBelongs to the Microsoft.Testing.Platform core libraryDiscussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions