Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7898919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:33:56+00:00 2026-06-03T08:33:56+00:00

I’m using Visual Studio 2010 Ultimate SP1. I have around 225 unit tests in

  • 0

I’m using Visual Studio 2010 Ultimate SP1. I have around 225 unit tests in my project, and they are all passing. One of those tests, however, reports 0% code coverage for the method it hits. When debugging, I can step through and see that it hits every line of the method. Yet in the code coverage report, it shows that the method isn’t covered at all. All other tests and methods work just fine with regards to code coverage.

I’ve tried the following with no success:

  • Moved the method being tested into another class.
  • Made the method
  • static vs. non-static.
  • Moved the test to another class.
  • Deleted all of my .testsetting files and recreated them from scratch
  • Wrote a different test to exercise the same method, with the same results
  • restarted VS
  • rebooted

In case it matters, the method was in the Global.asax file. However, I moved it to another class and it made no difference.

Any ideas?

Here is the method being tested.

 public void LogError(ILoggingService loggingService, IController controller)
    {
        if (loggingService == null)
            throw new ArgumentNullException("loggingService");

        if (controller == null)
            throw new ArgumentNullException("controller");

        Exception ex = Server.GetLastError();

        loggingService.LogException(ex.Message, ex.StackTrace, ApplicationName.VoucherLog, UserInfo.UserName);


        HttpException httpException = ex as HttpException;

        if (httpException == null)
        {
            var routeData = new RouteData();
            routeData.Values["controller"] = "Error";
            routeData.Values["action"] = "HttpError";

            Server.ClearError();

            var rc = new RequestContext(new HttpContextWrapper(Context), routeData);
            controller.Execute(rc);
        }
    }

The first 4 lines, where the exceptions are thrown, are hit by other tests and show up in the code coverage statistics. The remainder of the method is hit by the following test (as verified by debugging through it and seeing that each and every line is, in fact, executed), but does not show up in code coverage stats. Here is the test:

    [TestMethod]
    [HostType("Moles")]
    public void LogError()
    {
        DMVCommon.ApplicationName expectedApplication = DMVCommon.ApplicationName.VoucherLog;
        string expectedUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
        NotImplementedException expectedException = null;

        System.Web.Moles.MHttpServerUtility.AllInstances.GetLastError = (System.Web.HttpServerUtility server) =>
        {
            return expectedException;
        };

        System.Web.Moles.MHttpApplication.AllInstances.ContextGet = (System.Web.HttpApplication application) =>
        {
            return MvcMockHelpers.FakeHttpCurrentContext();
        };


        try
        {
            throw new NotImplementedException();
        }
        catch (NotImplementedException exc)
        {
            expectedException = exc;
            using (MvcApplication app = new MvcApplication())
            {
                bool called = false;

                Mock<ILoggingService> mockLoggingService = new Mock<ILoggingService>();
                mockLoggingService.Setup(a => a.LogException(expectedException.Message, expectedException.StackTrace, expectedApplication, expectedUser)).Callback(() => called = true);

                Mock<IController> mockController = new Mock<IController>();

                app.LogError(mockLoggingService.Object, mockController.Object);

                mockController.Verify(a => a.Execute(It.IsAny<System.Web.Routing.RequestContext>()), Times.Exactly(1));
                Assert.IsTrue(called);
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:33:58+00:00Added an answer on June 3, 2026 at 8:33 am

    This happens probably because of your usage of Moles – As the runner loads the assembly, Moles takes over and profiles the assembly instead of the coverage profiler.

    There has been known integration issues with coverage tools and Moles –
    In order for two .Net profilers (Moles & coverage) to work together they have to implement specific support for each other.

    Try to run without Moles and see what happens…

    Also see this as a similar example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.