If an assembly contains an app.config file, ConfigurationManager
will load it as long as it is in the same directory as the NUnit project that is executing through NUnit-Gui. To illustrate consider the following folder structure.
+ TestFolder
testProject.nunit
+ AssemblyAFolder
assemblyA.dll
assemblyA.dll.config
+ AssemblyBFolder
assemblyB.dll
assemblyB.dll.config
Both AssemblyA
and AssemblyB
exercise code that calls into ConfigurationManager
. If I run these test assemblies independently in NUnit-Gui, ConfigurationManager
will correctly resolve the local configuration files.
However, if I load testProject.nunit
into NUnit-Gui (which contains references to both AssemblyA
and AssemblyB
), ConfigurationManager
looks for the configuration file in TestFolder
regardless of which assembly is currently executing.
Is there a way to direct NUnit to reload the application configuration to the one present in the current assembly's directory?
Here are the contents of testProject.nunit
:
<NUnitProject>
<Settings activeconfig="Debug" />
<Config name="Debug" binpathtype="Auto">
<assembly path="AssemblyAFolder\assemblyA.dll" />
<assembly path="AssemblyBFolder\assemblyB.dll" />
</Config>
</NUnitProject>
Nunit is unable to locate the path of App.config File in our project. So we need to manually tell the Nunit where the App.config File is placed in our project (obviously on the root folder).
In my case , the project structure is as following
+ProjectWEBApp//web pages
+Modules
+aspx pages
+web.Config
+projectBusinesslogic //business logic .cs files
+Modules
+.cs
+ProjectTestName// a seperate Nunit test cases project
+Modules
+App.Config
the ProjectWebApp uses the references of projectBusinesslogic which contains the business logic. the +ProjectTestName uses the reference of projectBusinesslogic to perform test on the business logic. The problems start here, Nunit test project needs its own app.config file. it won't use web.config file as in case of projectBusinesslogic,so when you run Nunit it will prompt an error
-Null Reference exception.......object instant not set to ...........
Solution- When you run the Nunit GUI
and that is the simple solution for your problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With