Unit testing Class Library that needs .config file under Visual Studio Team System

Topics: Exception Handling Application Block, Logging Application Block
Dec 25, 2007 at 6:31 PM
Hi,

I'm trying to debug my class library that uses Exception Handling Application Block.
I'm using Unit testing within Test Project in Visual Studio Team System.

When I run the unit test the System.NullReferenceException happens in line:
_Hi,

I'm trying to debug my class library that uses Exception Handling Application Block.
I'm using Unit testing within Test Project in Visual Studio Team System.

When I run the unit test the System.NullReferenceException happens in line:

bool rethrow = ExceptionPolicy.HandleException(ex, "ClassLibrary1 A");

Test method TestProject1.Class1Test.ATest threw exception: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.._


My guess is that .config file is missing while the Unit test is running.
_How to fix this?

let's say my class library is "a.dll"
Placing "a.dll.config" in TestResults/XXXXX/OUT does not help.

Please help!
Daniel


Test method TestProject1.Class1Test.ATest threw exception: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.._


My guess is that .config file is missing when (and where) the Unit test is running.
How to fix this?

let's say my class library is "a.dll"
Placing "a.dll.config" in TestResults/XXXXX/OUT does not help.

Please help!
Daniel
Dec 26, 2007 at 8:12 PM
One option is, Add an app.config to your unit test project, and copy your config file contents to it.
( Note that you may need to removed some of the content of your .COnfig file, to fit it in to app.config, for example, if you are unit testing a web application, you need remove system.web section before copying over to unit test app.config)

- Neo.
Dec 29, 2007 at 12:12 PM
Neo, that helps! Thanks a lot!!!