Run unit tests in different appdomain with NUnit

后端 未结 3 907
梦毁少年i
梦毁少年i 2020-12-03 11:37

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 (use

相关标签:
3条回答
  • 2020-12-03 12:12

    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")
    }
    
    0 讨论(0)
  • 2020-12-03 12:18

    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.

    0 讨论(0)
  • 2020-12-03 12:28

    I don't think there is a way to solve it without re-writing parts of the NUnit code. It has been a while since I've been inside the NUnit code, but I am pretty sure the main app domain loading part has not changed.

    NUnit typically uses two app domains. The default one that is created when NUnit is run and a separate one to load the test assemblies and the assemblies they reference. It's main reason in doing this is to allow the unloading of the test assemblies. You can't unload a dll, but you can unload an appdomain.

    You might be able to run NUnit once per test and pass the test on the command line, but that's ugly and I'm not sure it will help.

    It might also be possible to leverage Action Attributes in NUnit 2.6, but you are going to do a lot of work in there to do it.

    You might also be able to create a new app domain in your setup method and call into it in each test. Awkward but possible.

    I'm sorry I don't have a more complete answer.

    0 讨论(0)
提交回复
热议问题