You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just started using xunit, and find it very nice to transition from MSTest (v2) to xunit. Nearly all my tests just worked after migrating.
I came accross one test suite of mine, where I want to test a mixed mode (c++/cli) DLL that I use in production.
In that DLL I implemented a ref class with some public static variables, that are initialized to reasonable default values in the static class constructor when used in production. For test purposes, I can alter the static variables and "inject" other behaviour into the class so that I can test what I want to test.
With MSTest, all this worked as expected, the static (ref class) constructor is executed once, before I alter the static variables from within the test, than the static variable is changed, and when "act"ing the test, the variable has my altered value.
With xunit (2.4.2, xunit.runner.visualstudio 2.4.5), this is not working.
The ref class constructor is executed before I alter the static variable, and is then afterwards again called, before I "act" the test, thus re-setting the static variable to the default value.
I created a small repo xunit-testfailure which reproduces the issue. Of course there are possible workarounds, I just don't understand why a static constructor is called twice...
The text was updated successfully, but these errors were encountered:
The reality is we have nothing to do with when static objects are initialized. That's down to coordination between the compiler and the runtime. Unfortunately, this isn't something that I'm honestly equipped to diagnose and fix (if such a fix is even reasonable).
That said, if there is a fix to be done on our side, it's probably in the core framework. I'm going to transfer this issue over there, and then mark it as help wanted.
I just started using xunit, and find it very nice to transition from MSTest (v2) to xunit. Nearly all my tests just worked after migrating.
I came accross one test suite of mine, where I want to test a mixed mode (c++/cli) DLL that I use in production.
In that DLL I implemented a ref class with some public static variables, that are initialized to reasonable default values in the static class constructor when used in production. For test purposes, I can alter the static variables and "inject" other behaviour into the class so that I can test what I want to test.
With MSTest, all this worked as expected, the static (ref class) constructor is executed once, before I alter the static variables from within the test, than the static variable is changed, and when "act"ing the test, the variable has my altered value.
With xunit (2.4.2, xunit.runner.visualstudio 2.4.5), this is not working.
The ref class constructor is executed before I alter the static variable, and is then afterwards again called, before I "act" the test, thus re-setting the static variable to the default value.
I created a small repo xunit-testfailure which reproduces the issue. Of course there are possible workarounds, I just don't understand why a static constructor is called twice...
The text was updated successfully, but these errors were encountered: