Search code examples
visual-studionunitnunit-3.0vstestvisual-studio-test-runner

NUnit is ignoring DomainUsage in the runsettings file


I'm running tests in Visual Studio using "Test Explorer" with NUnit and a .runsettings file (specified by choosing the option in the GUI "Select Settings File")

My settings file (called mytests.runsettings) is:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <RunConfiguration>
    <DisableAppDomain>True</DisableAppDomain>
  </RunConfiguration>
  <ForceListContent>true</ForceListContent>
  <NUnit>
    <DomainUsage>None</DomainUsage>
  </NUnit>
</RunSettings>

I have verified that it is loading this file (verified by adding the framework node and setting it to a fake version, which then results in an error).

But no matter what I do, it doesn't run without an AppDomain!

Running from the command line does work:

nunit3-console.exe --domain=None --inprocess MyTests.dll

What do i need to do to get it to use that setting in NUnit?


Solution

  • I don't believe you can do that.

    1. There is no recognized DomainUsage element under NUnit in the runsettings file. DomainUsage is an internally used property, which will be honored if set. But you can't set it that way. Your DomainUsage element is simply being ignored.

    2. If the adapter received your DisableAppDomain setting, then it would set DomainUsage to None. However, I don't believe it is actually receiving it.

    Point 2 requires some explanation. Note that I haven't worked on the adapter for a few years and I'm going from memory but here it is...

    The DisableAppDomain setting was added to allow Visual Studio to force NUnit to try to run without using an AppDomain. The Test Explorer is supposed to set things up so that it's possible to run that way, i.e. by making sure everything is already available in the current domain.

    In order to prevent misuse of the feature, I believe that Test Explorer always overrides any user-provided setting. Again, this is from memory of work that was done a few years ago, but it seems as if the results you are seeing validate it.

    The rationale for this past decision was that Test Explorer is completely responsible for setting up the Process and AppDomain used to run the tests. The user has no way to impact that and neither does NUnit. Of course, when using the console runner, that's not the case - control is in the hands of the user.

    Something else to investigate is why you feel the need to run without a test AppDomain being created. But that's probably another question. :-)

    I'll ask some other folks who may have a better memory than I to look at this as well.

    UPDATE:

    @Terje, who maintains the adapter now, replied and confirmed that there is no way to set DomainUsage in the runsettings file or any other way we know of when running under the test adapter. The docs have been corrected to avoid the implicit suggestion that it's possible.

    We believe, but have not confirmed experimentally, that TestExplorer creates it's own AppDomain whenever it uses this setting to suppress its creation by the test adapter.