Skip to content

Allow to inherit from fixture methods #1680

@gao-artur

Description

Hey. We have integrated OpenTelemetry using System.Diagnostics.ActivitySource in our services and now looking to improve observability in the end-to-end tests. We are using MsTest to run different scenarios, including calling web services (with OTel support), sending bus messages, accessing databases, etc.
We want to achieve the following with as less duplicate code as possible:

  • Assembly Initialize:
    • create a new ActivitySource
    • wrap the method logic with an Activity
  • Assembly Cleanup:
    • wrap the method logic with an Activity
    • dispose the ActivitySource created on Assembly Initialize
  • Class Initialize/Cleanup: wrap the method logic with an Activity
  • Test method: wrap the method logic with an Activity

The last point looks pretty simple. It can be achieved by deriving the TestMethodAttribute and overriding the Execute method. And by deriving from TestClassAttribute and overriding the GetTestMethodAttribute, we can simply replace the [TestClass] with our [TelemetryTestClass] and finish the task with minimal changes.
But unfortunately, it's impossible to do the same with Assembly and Class Initialize/Cleanup attributes.
Are there any extension points that would allow implementing it once and reusing it in all assemblies/classes? If not, would you consider providing such extension points in future releases?

AB#2332773

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions