Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestingPlatformBuilderHook -> GetEntryAssembly() issue #4312

Open
nbalu opened this issue Dec 10, 2024 · 2 comments
Open

TestingPlatformBuilderHook -> GetEntryAssembly() issue #4312

nbalu opened this issue Dec 10, 2024 · 2 comments

Comments

@nbalu
Copy link

nbalu commented Dec 10, 2024

Describe the bug

I've made my orchestration tool that's capable to load and execute the test assemblies. Though dynamic loading fails as the entry assembly is not referencing itself rather the entry assembly.

Steps To Reproduce

Create an executable project with TestPlatformBuilder.
Create a project that references MSTest.
Use the generated functionality to lookup and register the test.

0 tests will be loaded and executed as it references the entry assembly instead of itself.

(

public static void AddExtensions(ITestApplicationBuilder testApplicationBuilder, string[] arguments) => testApplicationBuilder.AddMSTest(() => [Assembly.GetEntryAssembly()!]);
)

Expected behavior

Tests should be loaded via the extension method.

Actual behavior

0 tests are discovered and added / loaded at all

Additional context

My problem is that the entry might not be the same assembly that holds the tests unfortunately.

@nohwnd
Copy link
Member

nohwnd commented Dec 11, 2024

Same problem can be observed in nativeaot mode, where the assembly property is null and we have to redefine the entrypoint to get reference to the current assembly as typeof(OurRootType).Assembly.

My desired solution was to change the AddExtensions method to pass in the this reference of the caller , or assembly - which is the type we emit into the executable assembly.

e.g.

AddExtensions(ITestApplicationBuilder testApplicationBuilder, Assembly testedAssembly, string[] arguments)

But I was not sure how useful it would be. So this is one more case where getting the type / assembly directly would be useful.

I ended up working around this problem to avoid changing the public api and breaking all extensions that integrate with it.

We could also work around this limitation of public api shape by adding a TestApplicationBuilderWithAssembly : ITestApplicationBuilder public type that would be a bag of info that we know we need right now. This will not limit our options for future if we need to transport more info. But it is a band-aid at best.

@Evangelink
Copy link
Member

I am not sure whether this is something we want to fix. We introduced the generated entry point only to help with transitioning from VSTest world but I think the right future and path forward is to have explicit Program.cs. It's like that for most web apps and no-one ever complained. It's also making it easier for everyone to understand what is run, how, what is the start and end... For example [AssemblyInit] and [AssemblyCleanup] are features that would not need to be introduced if we had explicit main from the start as we could simply wrap calls in try/finally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants