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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:10:22+00:00 2026-05-13T01:10:22+00:00

I am working on writing unit tests properly, and I wonder is it bad

  • 0

I am working on writing unit tests properly, and I wonder is it bad technique to test the result of a method under test by calling another method to verify the result?

ie. in the below example I can only check that an StoreObject method call was successful(ie. a object being stored in the cache) by calling either FetchObject or the HasCachedObjects property, both of which contain logic that should be tested separately. What would you do in this case where the result is hidden from the public API?

I have a Cache class:

public class Cache {

  private Dictionary<string, object> _Cache = null;

  public bool HasCachedObjects {
    get {
      if (_Cache.Count > 0) {
        return true;
      } else {
        return false;
      }
    }
  }

  public Cache() {
    _Cache = new Dictionary<string,object>();
  }

  public void StoreObject(string key, object obj) {
    _Cache[key] = obj;
  }

  public object FetchObject(string key) {
    if (_Cache.ContainsKey(key)) {
      return _Cache[key];
    }

    return null;
  }
}
  • 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-05-13T01:10:23+00:00Added an answer on May 13, 2026 at 1:10 am

    Don’t think of a test case as testing a method; think of it as testing a unit of functionality (or perhaps a use case).

    So your test might be StoreObject_WhenSuccessful_AddsToCache or some such.

    And yes, I’d confirm the test via the public API.

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

Sidebar

Related Questions

I'm writing Unit-Tests for an OK_Execute Command in an MvvM-Scenario. Now that's working fine
I'm working on writing a non-trivial unit test (perhaps better called a UI test?).
I am writing some unit tests to ensure that everything is working as supposed
I'm writing unit tests using Boost.Test against some old C math library. One of
I'm working on writing simple unit tests for a Rails 3 project, but I'm
I am writing unit test cases for a game I am working on. When
I am writing unit tests for service layer in my spring application. Here is
Is it common to write integration tests before writing unit tests? Is it conventional,
I am working on a C# WinForms application in VC# 2008 Express, writing unit
I'm writing some unit tests for one of my rails models. It's a large

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.