Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run unit tests in different appdomain with NUnit

I seem to be having an issue, the application we're using uses a Ninject kernel, and contains a particular configuration that's gathered with contents of the WCF call (username, token...).

Based on that a particular configuration the user is assigned rights on the app, this is shielded through a particular instance in the Ninject kernel.

We cannot just recompose the Ninject kernel, what we'd like to do is run a couple of Nunit tests, but run each of them in a separate app domain (recreating the kernel each time with different settings).

I've only found ways to run whole test projects in different app domains but not test per test.

Is there a way to solve this?

Unfortunately the Ninject configuration is not on our side, we have to 'live' with it this way.

like image 655
Snake Avatar asked Mar 09 '12 12:03

Snake


2 Answers

I needed to do the the exact same thing, so I created a library which basically takes the current test and re-executes it in a new AppDomain. It's a nuget package called NUnit.ApplicationDomain and is open source.

Example Code:

[Test, RunInApplicationDomain]
public void Method()
{
  Console.WriteLine("I'm in a different AppDomain")
}
like image 137
zastrowm Avatar answered Oct 25 '22 16:10

zastrowm


I'm not entirely sure about your question. However it seems like you need some kind of a custom implementation. Did you consider custom test attributes? Then may be configure each attribute to run in a different App Domain? I'm just spinning up some ideas, but there may be better ways of doing this.

like image 24
Spock Avatar answered Oct 25 '22 15:10

Spock