Tests can't be run in existing AppDomain

Bug #896615 reported by Roman Pushkov
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit V2
Fix Released
Medium
Charlie Poole

Bug Description

If I set Options.TestLoader.DomainUsage as DomainUsage.None and set Options.TestLoader.ProcessModel = ProcessModel.Single, test-doman-* AppDomain created otherwise, because these parameters set to Default.
It seems that problem is inside method TestLoader::MakeTestPackage in this code:

if (processModel != ProcessModel.Multiple && domainUsage == DomainUsage.Multiple
                && !package.Settings.Contains("DomainUsage"))
                package.Settings["DomainUsage"] = domainUsage;

Does the code needs to be changed to the following code?

if (processModel != ProcessModel.Multiple && domainUsage != DomainUsage.Multiple
                && !package.Settings.Contains("DomainUsage"))
                package.Settings["DomainUsage"] = domainUsage;

Related branches

Revision history for this message
Charlie Poole (charlie.poole) wrote :

Code doesn't exist in nunit-3.0... bug must be intended for nunitv2

affects: nunit-3.0 → nunitv2
Changed in nunitv2:
status: New → Triaged
importance: Undecided → Medium
assignee: nobody → Charlie Poole (charlie.poole)
milestone: none → 2.6.0
Revision history for this message
Charlie Poole (charlie.poole) wrote :

Are you editing the xml file to create these settings? The gui settings page doesn't support them.

Revision history for this message
Roman Pushkov (roman-pushkov) wrote :

I'm creating my own standalone application, which uses NUnit framework to make tests internally.
Necessary options was set using this code:

Services.UserSettings.SaveSetting("Options.TestLoader.DomainUsage", DomainUsage.None);
Services.UserSettings.SaveSetting("Options.TestLoader.ProcessModel", ProcessModel.Single);

When TestLoader was created, it creates new test-domain. I set a breakpoint inside and found a place in MakeTestPackage, where options was rewritten to Default.

Revision history for this message
Charlie Poole (charlie.poole) wrote :

You are right that the code in question is incorrect. NUnit only uses TestLoader for the Gui, which cannot run with DomainUsage.None, so this was never noticed before.

OTOH, the code you suggest doesn't work for all cases. What's intended is to prevent both ProcessModel and DomainUsage from being set to Multiple, which requires

if ( (processModel != ProcessModel.Multiple || domainUsage != DomainUsage.Multiple)
                && !package.Settings.Contains("DomainUsage"))
                package.Settings["DomainUsage"] = domainUsage;

I'm torn here. On the one hand, I'd like to fix this for you but on the other, I'm tempted to add 'domainUsage != domainUsage.None' to the statement, so that the Gui won't crash. I'll look to see if I can put that test in the Gui itself.

Changed in nunitv2:
status: Triaged → Fix Committed
Revision history for this message
Charlie Poole (charlie.poole) wrote :

This is now fixed (in the source) in a way that will work for you. However, I suggest you avoid using the Settings to control options for your use of NUnit. That approach will cause NUnit itself, both the Gui and Console runners, to use the settings you leave behind. A better approach for programmatic control is to place the options in the TestPackage you create. TestPackage settings will override anything in the general NUnit settings.

Changed in nunitv2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.