I have a bunch of xUnit tests to test various behaviours of a class whose behaviour is determined by environment variables. This isn't the problem. The problem is that environment variables are per-process, not per-thread, and the tests interfere with each other when run in parallel. Other than adding in mutexes etc., I've yet to find any way to control the parallelism for when the full suite of tests is run through visual studio (I know it can be done when run from command line, but that's not how most developers are going to work). There's obviously several possible solutions, including using something like the Fakes library to monkey patch the behaviour of Environment.GetEnvironmentVariable, or even re-writing the code under test to allow substituting in a different method of obtaining configuration settings, but it does seem like there should be an easier way.
Actually as it happens the only test that's really giving me grief is a specific test that's only ever meant to be run individually as needed to do some end-to-end testing (e.g. it sends out real emails etc.), but xUnit doesn't appear to provide a way to check for that either, which is a little annoying - in fact the way we prevent it from running as part of the ci build is to check that it's on a Windows machine as for now, individual devs generally work on Windows and ci runs on macs and linux boxes! The other option I'd considered was to have the test be skipped if you didn't have a debugger attached, but it's handy just to be able to 'run' it w/o debugging and see that it does everything expected.
Surely there are other developers out there that have had similar challenges?