-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Found two different objects associated with the same URI, '.../TestAgency'. #9
Comments
Looks like you are either trying to start two test agencies at once or starting an agency without terminating one that's already running. Since there can only be one Test Agency service running, there can only be one Test Engine using the default set of services. |
It looks like the When the adapter is used properly, this method will only be called once so this isn't an issue. It's only when it's created multiple times (when unit testing) that it might be a problem. |
Here's the call in question: |
OK, in your code, you tell the engine that it should run in process and without creating any appdomain. You want it to use the process you have already created and run in the primary domain, which I assume you have set up such that the tests will be found. However, you are using the default setup of the TestEngine, which gets initialized automatically when you ask for a runner. That default initialization includes the creation of some services you don't actually use. One of them is the TestAgency. There's no harm in this. It's the same as what I do in the NUnit adapter. It just means you can't create multiple TestEngines, which you appear to be doing in your tests. The easiest workaround is to do the initialization of the engine services yourself, before you ask for a runner, only including those services you will use. Take a look at nunit-agent to see how this is done there. The agent only runs tests in its own process, so it doesn't use TestAgency at all. |
Thanks for the info. I tried changing it to the following, but I'm still seeing that exception. 😞
How does the |
That looks good down to the point where you call |
If I change it to:
I get the following:
How does |
You left out ExtensionService. This should be OK if you didn't want any extensions but the code in DriverService depends on it's being there. This should be fixed. Meanwhile, just add it right after SettingsService - those two services are the two most likely to be needed by other services in the future. |
I've ended up with the following set, which seems to work:
I've tagged with |
I don't see anything missing, but do you actually need the ones you added? ProjectService is a no-op unless you add extensions for specific project types and I don't imagine you want to open nunit or vs project files. RuntimeFrameworkservice is used to select the required .NET runtime for a test, but you can't affect that without creating a new process. TestFilterService is needed if you want to parse text to create filters. I think the more natural starting place for you is the list of services used by the agent, from which you could remove what you don't need. I say that because you are basically in the same situation as the agent... you're in a process that has already been created... except that you don't even need to create new app domains. |
Of course, there is no loss to add a service you don't use, since it's already loaded. But in the future, some services will become extensions and adding them will mean you need to provide the extension assembly somewhere as well. I think it's also good documentation to only load the ones you actually need plus (for now) ExtensionService due to the bug I pointed out. |
I think they're all necessary. I tried removing each in turn and added it back the test runner failed (generally with null-ref exceptions). It didn't actually fail when SettingsService was removed. Is this strictly necessary? |
I added code to most services that use SettingsService to have a hard-coded default if it was not available. You would have to look at the failing service's startup code to see what it needs. If it seems as if there is no good reason for a particular failure, a bug report would be great. I think that the services should generally be as forgiving as possible when other services are not available. If nothing else, it makes testing easier. |
Anyway... they can't all be needed, else nunit-agent wouldn't start! |
Bear in mind that order of adding is significant - I wish it were not, but it is. :-) |
Removing either of these:
cause it to null-ref on this line: I'd dig more but our child minder is on holiday and we're potty training! 😉 |
No need... I think you are running into issue #1732, which has just been fixed for a 3.4.2 release. You can work around it by explicitly calling Load before you call Explore, CountTestCases or Run. |
I am using Test API and facing same issue, I am new to NUnit and looks like API has been changed and I am not able to follow steps mentioned to customize initialization of the engine I am using this method to get engine, engine = TestEngineActivator.CreateInstance(); |
@pamle117 The
UPDATE - Sorry, I realized I can't transfer this because it still needs to be worked in the tdnet adapter project. Please file your own issue under nunit-console, explaining what you are trying to accomplish and how you want to use the engine.
|
Oh I am sorry. I have created new issue under nunit console. Thanks! |
Any idea what might be going wrong here? Seems to happen pretty randomly inside my test runner unit tests. It has been a while since I wrestled with this kind of stuff. :(
The text was updated successfully, but these errors were encountered: