Skip to content

Migrate to xunit.v3#13482

Draft
Youssef1313 wants to merge 22 commits intomainfrom
dev/ygerges/mtp
Draft

Migrate to xunit.v3#13482
Youssef1313 wants to merge 22 commits intomainfrom
dev/ygerges/mtp

Conversation

@Youssef1313
Copy link
Copy Markdown
Member

No description provided.

@rainersigwald
Copy link
Copy Markdown
Member

fyi I'm working on this in #13215, but won't be mad if you beat me to it. Chasing what looks like some Windows hangs at the moment, and as a low-pri background thing.

@Youssef1313
Copy link
Copy Markdown
Member Author

Oh, I didn't know you are already working on it.

@Youssef1313
Copy link
Copy Markdown
Member Author

Youssef1313 commented Apr 2, 2026

@rainersigwald I tried to pull in some changes you did in the other PR here to see if it gets me here in a better state. We can sync next Tuesday to align the efforts.

Generally speaking, a big difference between the two PRs is that in this PR I'm running with MTP, while the other PR runs with VSTest. But I would think most test failures will be related to the xunit 2 to xunit 3 move and not VSTest/MTP differences. In addition, in this PR I'm keeping the tests wrapped in TestEnvironment.Create() and TestEnvironment.Dispose() to assert that the tests don't change env variables.

One thing to note is that xunit.v3 might be running the tests in a different order compared to xunit 2, which might (or might not) be the cause for some of the failures (i.e, some tests might have been modifying global state without resetting it - that was somehow unnoticed with xunit 2 but might become apparent now that the ordering changed)

@rainersigwald
Copy link
Copy Markdown
Member

In addition, in this PR I'm keeping the tests wrapped in TestEnvironment.Create() and TestEnvironment.Dispose() to assert that the tests don't change env variables.

I believe this is not currently working--my interpretation of a bunch of failures in my attempt was "something is making this work now and failing a bunch of tests that should have been failing before but weren't". I'd love to have all those tests fixed of course . . .

@Youssef1313
Copy link
Copy Markdown
Member Author

Youssef1313 commented Apr 2, 2026

In addition, in this PR I'm keeping the tests wrapped in TestEnvironment.Create() and TestEnvironment.Dispose() to assert that the tests don't change env variables.

I believe this is not currently working--my interpretation of a bunch of failures in my attempt was "something is making this work now and failing a bunch of tests that should have been failing before but weren't". I'd love to have all those tests fixed of course . . .

In the other PR, I commented on why the approach there won't work. But I think it might have been working on main already.

Comment on lines +23 to +24
var exceptionFilesBefore =
Directory.Exists(DebugUtils.DebugDumpPath) ? Directory.GetFiles(DebugUtils.DebugDumpPath, "MSBuild_*failure.txt") : Array.Empty<string>();
Copy link
Copy Markdown
Member Author

@Youssef1313 Youssef1313 Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some unknown reason, sometimes the DebugDumpPath directory isn't there on disk, and then GetFiles throws an exception if the directory doesn't exist.

Maybe there is some other previous test that deletes DebugDumpPath or something. Anyways, it should be safe to keep this change. It just means that future refactoring for how tests work is ideal to avoid this kind of cross-test dependency issues.

Comment on lines +27 to +29
private static string AssemblyLocation { get; } =
typeof(TaskHostFactory_Tests).Assembly.Location
?? Path.Combine(AppContext.BaseDirectory, "Microsoft.Build.Engine.UnitTests.dll");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • NOTE 1: Under .NET Framework, the assembly is now the .exe which Assembly.Location will provide correctly.
  • NOTE 2: In the case of Assembly.Location being null (unlikely to happen for .NET Framework), we still use AppContext.BaseDirectory and then get the dll. If this ever happened for .NET Framework, we would need to add extra condition to either find .dll or .exe for .NET Framework. But so far Assembly.Location simply works just fine.

ParallelConsoleLogger cl2 = new ParallelConsoleLogger(LoggerVerbosity.Minimal, sc.Write, null, null);
EventSourceSink es = new EventSourceSink();
cl2.Initialize(es);
cl2.Parameters = "ShowEnvironment";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: This line will lead to:

Traits.LogAllEnvironmentVariables = true;

So, we ensure we get back the static state to its original value (should be false).

There is some other test that would fail if Traits.LogAllEnvironmentVariables is true (I don't recall which one now).

In current main, DisplayEnvironmentInMinimal is run after that test so everything kinda works fine.

With xunit.v3, the order changed and now DisplayEnvironmentInMinimal is run earlier, causing the other test to fail.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants