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 9180301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:00:54+00:00 2026-06-17T18:00:54+00:00

I was looking over a fairly modern project created with a big emphasis on

  • 0

I was looking over a fairly modern project created with a big emphasis on unit testing. In accordance with old adage “every problem in object oriented programming can be solved by introducing new layer of indirection” this project was sporting multiple layers of indirection. The side-effect was that fair amount of code looked like following:

public bool IsOverdraft)
{
    balanceProvider.IsOverdraft();
}

Now, because of the empahsis on unit testing and maintaining high code coverage, every piece of code had unit tests written against it.Therefore this little method would have three unit tests present. Those would check:

  1. If balanceProvider.IsOverdraft() returns true then IsOverdraft should return true
  2. If balanceProvider.IsOverdraft() returns false then IsOverdraft should return false
  3. If balanceProvider throws an exception then IsOverdraft should rethrow the same exception

To make things worse, the mocking framework used (NMock2) accepted method names as string literals, as follows:

NMock2.Expect.Once.On(mockBalanceProvider)
    .Method("IsOverdraft")
    .Will(NMock2.Return.Value(false));

That obviously made “red, green, refactor” rule into “red, green, refactor, rename in test, rename in test, rename in test”. Using differnt mocking framework like Moq, would help with refactoring, but it would require a sweep trough all existing unit tests.

What is the ideal way to handle this situation?

A) Keep smaller levels of layers, so that those forwarding calls do not happen anymore.

B) Do not test those forwarding methods, as they do not contain business logic. For purposes of coverage marked them all with ExcludeFromCodeCoverage attribute.

C) Test only if proper method is invoked, without checking return values, exceptions, etc.

D) Suck it up, and keep writing those tests 😉

  • 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-17T18:00:55+00:00Added an answer on June 17, 2026 at 6:00 pm

    Either B or C. That’s the problem with such general requirements (“every method must have unit test, every line of code needs to be covered”) – sometimes, benefit they provide is not worth the cost. If it’s something you came up with, I suggest rethinking this approach. The “we must have 95% code coverage” might be appealing on paper but in practice it quickly spawns problems like the one you have.

    Also, the code you’re testing is something I’d call trivial code. Having 3 tests for it is most likely overkill. For that single line of code, you’ll have to maintain like 40 more. Unless your software is mission critical (which might explain high-coverage requirement), I’d skip those tests.

    One of the (IMHO) most pragmatic advices on this topic was provided by Kent Beck some time ago on this very site and I expanded a bit on those thoughts with in my blog posts – What should you test?

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

Sidebar

Related Questions

I have taken over a project and am fairly new to cocotouch. I was
I've just started looking at a project that has >20k unit tests written in
I am still fairly new to Java programming and I was looking over a
Fairly straight-forward question here. Been looking over some code and I've seen a function
Looking over the magento 1.5 schema I cannot seem to figure out how a
I am looking over csipsimple app - uses sip calls, registers. I also found
I have been looking over the internet for a while about this, but it
I have been looking over this code for the past hour, I cant see
I was looking over the code for qunit. My question is why would you
I have a little / weird behaviour here and Im looking over internet and

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.