NUnit GUI is not finding the app.config file

488 views Asked by At

I have an ASP.NET MVC application that I'm using NUnit to write tests for. The NUnit GUI is unable to find the app.config when I run the test. My NUnit test project is located in the bin/debug folder along with a copy of the app.config file:

My NUnit project has the following settings:

<NUnitProject>
    <Settings activeconfig="Default"
              processModel="Default"
              domainUsage="Default"
              appbase="C:\Sandbox\HB2\HB2.UnitTests" />

    <Config name="Default"
            binpathtype="Auto"
            configfile="app.config"
            path="C:\Sandbox\HB2\HB2.UnitTests\bin\debug\">

        <assembly path="bin\debug\HB2.UnitTests.dll" />

    </Config>
</NUnitProject>

From several articles I've read I would think that NUnit should be able to find the app.config file, but it doesn't. What's wrong?

1

There are 1 answers

1
forsvarir On

You seem to be using an NUnit project file. If so, you're going to have a file something like MyTestProject.nunit. When you're using a project file, rather than using the default app.config for a particular assembly included in the project, NUnit will by default look for a file with the same name as the Nunit project file. So in my example it would be MyTestProject.config. You haven't said what your project is so I can't give you an exact answer...

It works this way, because it makes it explicit which config to use which becomes important once you start including more assemblies in your project file. If you're always going to be using the config from a particular assembly then a simple way to keep the two synchronised is to setup a post build step to copy the config from that assembly to the .config location.

If you open an individual assembly in the GUI, rather than working with a project file then it will pick up the config associated with that dll (so HB2.UnitTests.dll.config in your example)

When I edited your question, I noticed that you're setting the config file to use in your project file. You're setting it to the wrong thing however. When you compile a project that produces a class library, the app.config is renamed by the compilation. As I've said above, this is typically <ouputassembly>.config. So, you should update this line in your project file:

<Config name="Default" binpathtype="Auto" configfile="app.config" 
        path="C:\Sandbox\HB2\HB2.UnitTests\bin\debug\">

To this:

<Config name="Default" binpathtype="Auto" configfile="HB2.UnitTests.dll" 
        path="C:\Sandbox\HB2\HB2.UnitTests\bin\debug\">