Passing data to a test within a custom test runner

Asked by Michael

Hi

I'm attempting to write a custom NUnit test runner to integrate into our application and I've managed to get a TestRunner object created and running some tests. Next I would like to be able to pass some data into the TestRunner for the tests to use.

At the moment I have created a class that implements IService and I add an instance into the NUnit ServiceManager class. A setup method, test method, etc, then uses the ServiceManager.Services to locate the object and can then access the data.

This seems to work, but I was wondering if this is the correct way to do this. Are there any easier/simplier/better ways of doing this and what gotchas should I look out for?

Kind Regards

Michael

Question information

Language:
English Edit question
Status:
Answered
For:
NUnit V2 Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Charlie Poole (charlie.poole) said :
#1

Your best source of info is the source code of NUnit itself.

NUnit's own TestRunners are not services. Rather you will find that they are
created for use as needed, using a factory to determine the best runner to
create depending on the settings of each TestPackage.

Services, in the NUnit design, are long-running objects that are accessed
through the service manager - often by TestRunners.

If you examine the code of the console runner dll, you will see a fairly
good example of how to initialize the needed services and then create
a runner. For a more complex example, see the Gui runner, where
TestRunner creation takes place in the TestLoader.cs class.

Charlie

On Thu, Mar 10, 2011 at 11:30 PM, Michael
<email address hidden> wrote:
> New question #148671 on NUnit V2:
> https://answers.launchpad.net/nunitv2/+question/148671
>
> Hi
>
> I'm attempting to write a custom NUnit test runner to integrate into our application and I've managed to get a TestRunner object created and running some tests. Next I would like to be able to pass some data into the TestRunner for the tests to use.
>
> At the moment I have created a class that implements IService and I add an instance into the NUnit ServiceManager class. A setup method, test method, etc, then uses the ServiceManager.Services to locate the object and can then access the data.
>
> This seems to work, but I was wondering if this is the correct way to do this. Are there any easier/simplier/better ways of doing this and what gotchas should I look out for?
>
> Kind Regards
>
> Michael
>
> --
> You received this question notification because you are an answer
> contact for NUnit V2.
>

Can you help with this problem?

Provide an answer of your own, or ask Michael for more information if necessary.

To post a message you must log in.