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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:44:02+00:00 2026-05-22T16:44:02+00:00

Imagine unit testing the following sample scenario. Let’s say I’ve mocked out the CustomerDAO

  • 0

Imagine unit testing the following sample scenario. Let’s say I’ve mocked out the CustomerDAO in order to return a valid customer and customer orders. Testing this scenario is fairly easy. Except when I get to testing the boolean for whether or not a customer has orders. In some real world scenarios they will not have orders. So do I need to add some condition in my mock DAO that will return a customer with no orders, and then test that as well? Now imagine it is much more complicated and there are several pieces of the DTO that could contain various bits of information depending on the real results coming back from the database. Do I need to test all of those various conditions?

public class Manager {

    public CustomerDTO getCustomerInformation() {

        CustomerDAO customerDAO = new CustomerDAO();

        CustomerDTO customerDTO = new CustomerDTO();
        customerDTO.setCustomer(customerDAO.getCustomer(1));
        customerDTO.setCustomerOrders(customerDAO.getCustomerOrders(1));
        if (!customerDTO.getCustomerOrders.isEmpty()) {
            customerDTO.setHasCustomerOrders(true);
        }

        return customerDTO;
    }
}
  • 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-22T16:44:03+00:00Added an answer on May 22, 2026 at 4:44 pm

    In short, I think yes you should test that when the DAO returns various things that the expected state exists on the DTO. Otherwise how can you have an confidence that the DTO will be an accurate representation of the data that was in the datastore?

    You should create either a mock DAO per test with the required data for the test, or a mock DAO for each state that needs to be tested.

    I’d probably have tests like:

    CustomerHasOrders_WhenDaoReturnsNoOrders_ReturnsFalse

    CustomerHasOrders_WhenDaoReturnsOrders_ReturnsTrue

    GetCustomer_WhenDaoReturnsCustomer_CustomerIsSame

    GetCustomerOrders_WhenDaoReturnsOrders_OrdersAreTheSame

    GetCustomerOrders_WhenDaoReturnsNoOrders_OrdersAreEmpty

    and then tests for what happens if any of the calls to the Dao fail…

    In this example it seems that the flag is redundant in the DTO, as it is just different representations of other data. You could implement that as an extension method on CustomerDTO, or some logic in the setCustomerOrders. If the DTO is to be sent over the wire and the functionality won’t neccessarily be there then you could exclude the property and the client could just do the check to see if there are any orders in the same way you are customerDTO.getCustomerOrders.isEmpty()

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

Sidebar

Related Questions

How can I mock a DataServiceQuery for unit testing purpose? Long Details follow: Imagine
I keep reading a lot of opinions in favor of Unit Testing, which is
I'd like to know if there are some unit testing frameworks which are capable
How do you do unit testing when you have some general unit tests more
I'm trying to figure out the best way of writing a unit test for
Imagine the following two classes of a chess game: TChessBoard = class private FBoard
I always had the notion that when you do unit testing, you have to
I am new to unit testing/TDD and having problem getting my head certain aspects
I've read a few threads on SO about usefulness of unit-testing various applications. The
I am unit testing mercurial integration and have a test class which currently creates

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.