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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:47:42+00:00 2026-06-10T04:47:42+00:00

when you write a test for the logic layer, you mock the data access

  • 0

when you write a test for the logic layer, you mock the data access layer that’s used, because you don’t want the test cases to be dependent on each other.

But what about lookup tables ?
lets say you have a logic that calculcates value depending on size in Sizes table:

Small 1
Medium 2
Large 3

Now, do you mock this table somehow in your test? using a dictionary for ex.? when the table changes (a real config table will contain hundreds of values, and sometimes will not be in simple key-value form) how do you keep code and table insync?

or you bend this rule… and get values directly from database?
but what if tomorrow i change the data source? or i cannot access the database somehow? aren’t test cases supposed to run in whatever conditions ?

what’s the best approach?

  • 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-10T04:47:43+00:00Added an answer on June 10, 2026 at 4:47 am

    I would still mock the lookup table, even if for the ‘happy’ testing scenarios you just return the real data returned from the database.

    But then you have the flexibility to test edge cases, e.g. where data has been deleted from the database, or if no data is returned.

    e.g.

    // Happy tests:
    Mock.Setup for GetLookupData() => return FetchRealDataHere();
    Assert.AreEqual(3, Mock.Object.CountOfSizes()); // Ensure that Small, Medium and Large
    ... Do Good scenario unit Tests here
    
    // Test Edge cases / destructive tests
    Mock.Setup for GetLookupData() => return new Collection() [{ Small, 1}] [{ Medium 2}] -   // But omit large
    ... Exception case Unit tests here, e.g. Try and Insert a Large product here.
    
    // Test empty collection
    Mock.Setup for GetLookupData() => return new Collection() [Empty]
    //  Assert that "NoItemsFoundException" was thrown by your logic here
    
    // Handle empty collection
    Mock.Setup for GetLookupData() => return new Collection() [Empty]
    

    Edit I’ve updated the pseudo Mock setup / Unit test code for the updated comment below.

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

Sidebar

Related Questions

I want to write some test cases for my web app, but stuck at
Using Nunit, I want to be able to write a test fixture that will
I'm trying to write a rspec spec to test that my logic is able
How to write test in Nunit to test that only one instance is created
Hi I am learning to write test cases with Rspec in ruby and am
I want to know the best way of testing data access functionality. I know
I have been reading a lot about test-driven development and decided that I want
I'd like to write a logic test to test for the case when [super
I want to write an unit test case to test the code in IBAction
I want to write a series of delegates that call one another. It's a

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.