Warning regarding the usage of MSTestThreadApartmentState set to STA in .NET 8.0 #4168
-
Hello, in the company I work at, we are in the process of migrating to .NET 8.0 one of our software programs and are running into a problem while migrating the tests, we have a propietary test framework for UI that allows for speedy and somewhat reliable UI tests, this test framework relied on mstest's main thread being STA to boot up the UI and directly manipulate it in search of any controls, behaviors, whatever you might need. This STA main thread changed to MTA in .NET 8.0 so I went out and found that MSTest 3.4.0 or later introduce STATestClass and STATestMethod, both of which kind of fix the issue, but after investing some time, I found out that they prompt MSTest to start the test method in a STA thread and afterwards, terminate it when the test ends, closing the UI as well. Because of this we become unable to interact with the UI in later tests not even using the Application.Current.Dispatcher solves this issue. It might be related to the UI being closed at the end of the first test. Investigating a little bit further, I found the .runsettings parameter MSTestThreadApartmentState, which can be set to either STA or MTA so I opted for setting it it STA and everything runs butter smooth, like in net framework. The question I have is that a warning is raised at the start stating that setting MSTestThreadApartmentState to STA is not allowed for NET 8.0 but it still works. Is this warning raised because sometime in the future this behavior will be dropped and we will run into this issue again or are there any other concerns I should be aware about setting MSTestThreadApartmentState to STA exclusively for running UI tests? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Which version of MSTest are you using? Could you please provide the exact warning message? Looking at the current codebase, the only STA related message is when setting STA thread on non-windows OSes. |
Beta Was this translation helpful? Give feedback.
Found it, the warning is coming from https://github.com/microsoft/vstest because this platform doesn't support the entry for .NET Core but we are handling it on MSTest side. You can safely ignore the warning, I don't think VSTest will want to remove the warning as from the platform point of view this setting is not handled.
I would recommend you to consider migrating to our new testing platform https://devblogs.microsoft.com/dotnet/introducing-ms-test-runner/ which would not have the warning and provides improved stability, features and performance.