No ProjectService instantiated in CreateDomain

Bug #928421 reported by Julian Taylor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit V2
Invalid
Undecided
Unassigned

Bug Description

monodevelop was ported to nunit 2.5 in ubuntu.
Unfortunatly it does not work properly to ProjectService being null in the CreateDomain call, leading to NullReference exception.
see bug 889241

I'm not very familiar with the code, so I can't judge if monodevelop is using nunit wrong, it is a bug in porting it to 2.5 or a bug in nunit 2.5
The issue was introduced in nunit revision 3127

There is monodevelops use of CreateDomain:
http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/precise/monodevelop/precise/view/head:/src/addins/NUnit/Services/ExternalTestRunner.cs#L88

Attached a patch to nunit that appears to fix the issue.

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

There are a couple of problems with this bug and the proposed patch...

1. DomainManager and ProjectService are two internal services used by
NUnit. Services never instantiate other services, since that would
require them to know about the existence of other services. All
services must be created before any of them are initialized. NUnit
does this in each of it's main executables. It's fine for a single
service like DomainManager to be instantiated and executed on its own
if you need it. That's how we test it, in fact. But if you need
multiple services, you should create and initialize them all in one
place, following a pattern similar to that used in the console runner.

2. But more significantly, it's not clear why the NAnt task needs this
service at all. It uses a TestPackage to describe the tests to be run.
A TestPackage never contains an NUnit project but has a list of
assemblies. Can you explain how it is that the ProjectService ends up
being required?

Charlie

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

Sorry, I misunderstood and confused the issue. The first issue remains the same, however.

Services in NUnit are instantiated by the mainline code. Where dependencies exist, as in
the case of DomainManager, which depends on the ProjectService service and the
UserSettings service, those services must be created and initialized before _any_
service is used.

So your code should look something like what console runner does, with the exception that
you only need to instantiate and initialize DomainManager and its dependencies. I didn't
recheck what the dependencies are, but assuming it's only the two above, your code
would look like this:

   ServiceManager.Services.AddService( new SettingsService() );
   ServiceManager.Services.AddService( new ProjectService() );
   ServiceManager.Services.AddService( new DomainManager() );

   ServiceManager.Services.InitializeServices();

I'm rejecting the bug because it can't be fixed in NUnit without breaking NUnit.

Charlie

Changed in nunitv2:
status: New → Invalid
Revision history for this message
Julian Taylor (jtaylor) wrote :

how is a program supposed to know which services it needs to start? or is there a StartAllServices function?
At least a better error message than a nullreference exception would be nice.

is nunit supposed to be used this way at all?
its not very good to break all programs using it when a new service dependency is introduced like in this case.

Are similar things to be expected in nunit 2.6?

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.