Hi,
> I have an issue getting coverage using NUnit on my logging code.
> For example, I have a lot of code that looks like the following:
>
> public class FuBar
> {
>
> private static ILog log = LogManager.GetLogger(typeof(FuBar));
>
> public FuBar(){}
>
> public int AddSomething(int a, int b)
> {
> if(log.IsDebugEnabled)
> {
> log.Debug("This code is never hit during unit
> testing);
> }
> return a + b;
> }
> }
>
> When I write an NUnit test for this example, I will get
> coverage for every line but the log.Debug...
... which, of course, indicates that IsDebugEnabled is false.
If you want to test that code, then you need to enable it in
some way- either in your test code or via some config, as you
are trying to do.
> Does anybody have any suggestions for this? I tried to add an
> app.config with the log4net settings to the test project.
> However, for some odd reason, it only seems to work
> inconsistently. In addition, our build guys prefer that we
> don't add app.config files to test projects.
When you say an "App.config" do you mean, literally, a file
of that name like you use in a VS exe project? Usually,
tests are dlls and VS will not do a copy/rename of those
files. Have you read the section of the docs about how
to set up a config file for your tests?
Of course, if your "build guys" are unhappy with needing
to deploy a test.dll.config with your test.dll, that's
a problem. Apparently, they are not aware of who is
providing a service to whom in your relationship. :-)
Charlie