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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:11:26+00:00 2026-05-26T16:11:26+00:00

I am wriring unit test cases for an existing system. The architecture for the

  • 0

I am wriring unit test cases for an existing system. The architecture for the underlying classes if very complex in itself.

Blockquote
RequestHanndler ==> processes ==> Order ===> is dependent on ==> service layer == connected to ==> DB layer.

I am writing a test case for RequestHandler. The method in test(doProcess()) creates a new instance of Order class. Order class itself has very tight dependency on the service layer. I want to create an atomic test case, so, not any other layer of code will be executed.

What should the best process to create test cases for these scenrios?

  • 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-26T16:11:27+00:00Added an answer on May 26, 2026 at 4:11 pm

    It might get a bit complicated when you want to write unit-tests for tighly coupled code. To make uni-testing easier you should better rely on abstractions and not on real implementations. E.g. the Order class shouldn’t depend on the real implementation of the service layer, instead introduce an interface which is much easier to mock instead of a class which might be set to final.

    Since your RequestHandler is responsible for creating the Order instances you’ll have to provide a way to mock out the order class in unit-tests. A simply way is to create a protected method that simply creates a new order instance.

    protected Order createOrder(String someParam) {
      return new Order(someParam);
    }
    

    In your Unit-Tests you can now extend the class and overwrite the factory-method.
    Using Mockito this would look like:

    protected Order createOrder(String someParam) {
      Order order = Mockito.mock(Order.class); // create mock object
      // configure mock to return someParam when 
      //  String Order#getSomeParam() gets invoked
      Mockito.doReturn(someParam).when(order).getSomeParam(); 
      return order;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing Unit test cases in Visual Studio 2008. I'm facing a weird problem.
I got a very intersting question while writing a unit test. Can I test
I am writing my unit test cases for a Java project using Scala (JUnit
When writing unit tests, it is normally advisable to test the edge cases. However,
I am writing unit test cases for a game I am working on. When
I am writing an unit test for a mvc web application that checks if
I'm writing a unit test for a method that packs boolean values into a
I'm writing a unit test and can't remember the syntax for initializing a string
I am writing some unit test and I have a unit testing base class
I'm writing a unit test for a Text Scrubber utility that will remove any

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.