Running specific NUnit tests to report only the coverage of a specific assembly with NCover

If you have one NUnit test project per Microsoft Visual Studio solution, to test all the projects (assemblies) in the solution, running NCover on the NUnit test assembly, all NUnit tests will be run and the coverage of all assemblies will be reported, when you are just interested in a specific assembly, you can let NCover run only specific NUnit tests.
This can be done in 2 ways:

– Specifying the namespace to test (in my case, preferable)
– Using the NUnit attribute [Category]

Specifying the namespace to test (in my case, preferable)

image 
In this way you don’t have to change you’re NUnit test code and because all NUnit tests of a specific assembly have a specific namespace, I can let NCover only run an report the coverage of a specific assemlby (subsystem).

Using the NUnit [Category] attibute
If you want to report the coverage of a specific group of NUnit tests, you can apply a category on the NUnit test in the group. NCover will only run and report the coverage of these NUnit tests.

        [Test]
        [Category("MyCustomer.MyProduct.MySubsytem.MyCategory")]
        public void TestForASpecificFunctionInASpecificAssemlby()
        {

        }

In NCover you can report the coverage of this specific NUnit tests category by using the values:

 image

How to skip NUnit tests during continuous integration build

Our continuous integration build server, runs all NUnit tests defined in a Microsoft Visual Studio solution file, but some NUnit tests are just created for integration testing. If you want to skip these tests you can use the NUnit attribute [Explicit]. These NUnit tests are only run when explicitly called from the nunit-console.exe command prompt. During the continuous integration build, these NUnit tests will be skipped.

        [Test]
        [Explicit("Can't be run on build server, no IIS server on build server")]
        public void IisIntegrationTest()
        {

        }

Reading and changing Log4Net configuration at runtime

You can read and change the Log4Net configuration at runtime, the following code, shows the eventlogname en eventlogsource for each eventlogappender defined, but if you change the eventLogAppender object properties the configuration will be changed.

            XmlConfigurator.Configure(new FileInfo(string.Format("{0}.config", @"C:\Temp\TestApplication.exe.config")));
            var repository = LogManager.GetRepository() as Hierarchy;
            if (repository != null)
            {
                var appenders = repository.GetAppenders();
                if (appenders != null)
                {
                    foreach (var appender in appenders)
                    {
                        if (appender is EventLogAppender)
                        {
                            var eventLogAppender = appender as EventLogAppender;
                            Console.WriteLine(string.Format("Eventlogname [{0}] and Eventlogsource [{1}] ", eventLogAppender.LogName, eventLogAppender.ApplicationName));
                        }
                    }
                }
            }