microsoft / testfx

MSTest framework and adapter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Unloading of assemblies using MSTest.Sdk/3.x.x

MarcZw opened this issue · comments

Question

Is there a way to unload assemblies using the MSTest.Sdk/3.x.x?

Problem

When registering MSTest via the extension point you need to provide an Assembly loaded in the default AssemblyLoadContext.
However, after loading this Assembly the corresponding .dll file gets locked from any io-operation, which the program needs.

See the code below for the current way of loading assemblies

TestApplication

var builder = await TestApplication.CreateBuilderAsync([]);

builder.AddMSTest(() =>
{
    var assembly = Assembly.LoadFrom(_assemblyPath);
    return [assembly];
});

using var app = await builder.BuildAsync();
await app.RunAsync();

Would you mind providing more details about the use case you are trying to cover?

At the moment the program (Stryker.NET) does an initial test run of the unit tests to determine whether any tests are failing before mutating the source code. To run these unit tests, the mstest extension needs a reference to an assembly loaded in the default loading context.

After the initial test run has finished, Stryker mutates the source code and tries to inject it in the .dll of the already ran unit tests.
Unfortunately this injecting will always fail, because the file is locked by loading the assembly into the default loading context.

After the initial test run has finished, Stryker mutates the source code and tries to inject it in the .dll of the already ran unit tests.
Unfortunately this injecting will always fail, because the file is locked by loading the assembly into the default loading context.

Why don't shutdown the app, instrument(I suppose you're rewriting it on disk and you're now using a profiler) and restart it?