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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:49:15+00:00 2026-05-20T03:49:15+00:00

I have a REST web-service interface that calls-down to a service layer which orchestrates

  • 0

I have a REST web-service interface that calls-down to a service layer which orchestrates the creation, deletion, etc. of various objects in an entity-layer. These entity-layer objects ultimately map to database records. I have a number of unit tests (in nunit, it a c# application) that test this interface by sending http requests.

Consider my testing of a web service request that creates a some entity-layer object. I obviously want to verify that the web service considers the request to have been processed correctly, by checking the http status that it returns to me plus some data in the response body. I also want to independently verify that the correct database records have been created. I have a couple of ways (that I can think of) to do this:

  • The easiest way is to use existing ‘reader’ classes in the entity layer to read and validate the database entries. This is easy because they incorporate the validation and consistency logic for the entities they deal with, and using them is simple. I am uneasy about this, though, because I would be using the code I’m testing as part of the test. This seems to violate some principle of separation of concerns, and also introduce the possibility of an entity-layer bug causing the object creation to fail but appear to the unit test to have succeeded.

  • Alternatively, the test code could go straight to the database and do the checks itself. But then I’m embedding details about object storage and consistency rules in the test – which makes the test brittle if those details change, and also effectively means re-implementing, in the unit tests, the code I’ve already written in the entity layer.

I wonder what people think of the trade-offs involved with these (and maybe other) options, and what (if any) is the best practice? I’m not sure if there is a right or wrong answer, but I’ve wondered about it for a while and interested in other opinions.

EDIT

To clarify, I save separate test suites for the service-layer and the entity-layer. The concerns I have expressed — using tested code in a test — also apply to these tests.

  • 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-20T03:49:16+00:00Added an answer on May 20, 2026 at 3:49 am

    We see two different tests, a test of the service methods and a test of the webclient.

    For testing the service methods (like a reader), you may want to create a database with predefined values (test data), call the reader, and test, if the readers output matches the test data in the required way.

    Once you’ve tested the service methods, you can move to the next test level and test the web client, again using the same test data but now testing if data shown on the web client matches the test data in the required way. On this test level, you can “trust” the readers (because they have been tested before).


    Maybe you feel more comforable if you separate between “unit testing” and “integration testing”. For unit testing, verify that a compilation unit works as required. This could be testing the reader: you populate the database with defined data, call findAll() (or something else), and assert that the test data and only the test data is in the result.

    The other test is an integration test – there you verify, that service layer and entity layer work together as expected. Same with testing the web client: you verify that the client / service layer works as required.

    And for integration tests I don’t see any reason to not use (tested) service layer methods.

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

Sidebar

Related Questions

I have a web service class that the rest of the framework depends on
We have a web application providing a service using a simple REST interface (GET/POST
I have a REST web service that returns an xml result like this: -
I have a REST web service that returns a structure containing an array of
I have a REST web service that returns a javax.ws.rs.core.Response entity. When I run
I have a C# WCF REST Service which allows the addition of a bookmark,
I have an application with a REST style interface that takes XML documents via
I ve created a sample REST web service which writes some data in a
I have created a simple Northwind's Product REST Web Service in WCF at /Northwind/Product
I am doing multiple HTTP POST to a REST web service that I created.

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.