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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:25:30+00:00 2026-05-18T10:25:30+00:00

This is pretty basic question around unit testing. I have a method e.g. GetOrderDetails

  • 0

This is pretty basic question around unit testing.

I have a method e.g. GetOrderDetails which calls a Repository to fetch order details. I have a mock repository which can be setup to return stock responses.

For testing GetOrderDetails method, I’ll at least use the following cases –

Repository call fails

  1. with an error code
  2. with an Exception

Repository call succeeded

  1. returned zero result
  2. returned one result
  3. returned more than one result

Should I be writing a single Test method to test above scenarios or should it really be a seperate test method for each of the above scenario?

I believe, breaking it down into multiple test methods would at least provide the following benefits
1. higher isolation in case of test failures
2. amount of code within a test method is less
3. each test method will have a single repository setup responsibility e.g. either setup for no result, or setup for multiple results etc

Could you please help with your views around this?

  • 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-18T10:25:30+00:00Added an answer on May 18, 2026 at 10:25 am

    I would write a separate unit test for each case. Basically every time you write an if or a switch inside the method you are testing it implies different unit tests to handle each case. The reason for this is that the arrange part of your unit test will be different based on which route you would like your code to take (different mock expectations, property setups, …). Also I would recommend you to organize your unit test in the following three parts:

    // arrange
    // -> prepare mock objects, properties, setup expectations
    
    // act
    // -> invoke the method your are testing
    
    // assert
    // -> assert on the results returned by the method your are testing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is a pretty basic question, but after Googling around I can't
I realize this question is pretty basic, but I'm really stuck. I have a
This obviously is pretty basic question but I haven't found my way around this:
This is a pretty basic MPI question, but I can't wrap my head around
This is a pretty basic question. Since browsers have a culture setting that the
This is a pretty basic question but I'm still unsure: If I have a
this should be a pretty basic question. I would like to have some html
Im sure this question is pretty basic but im new. Now I have a
this is a pretty basic question but I can't seem to get it right.
This is a pretty basic question but I can't find a good answer for

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.