Say I have a Service Layer method like this:

public void TestMethod()
   DomainObject domainObject = new DomainObject();

TestMethod looks like this in the Domain Layer:

public void TestMethod()

Is it bad practice to Unit Test this Service Layer method? The reason I ask is because the Domain Object.TestMethod calls three other methods. My reading tells me that you should only test one method per unit test.

  • 6
    Consider this, if that test fails, how do you know which of the three methods it was testing failed? Commented May 16, 2017 at 16:28
  • 2
    Possible duplicate of How should I test the functionality of a function that uses other functions in it?
    – gnat
    Commented May 16, 2017 at 16:41
  • 2
    I think your question is a bit confusing. Your service layer does not know how DomainObject.TestMethod is implemented. The implementation in your domain layer is completely irrelevant to whether you should unit test your service layer. Commented May 16, 2017 at 17:08
  • 1
    can you change the names of the methods and objects to something meaningful? I mean do you have a test called TestMethodTestMethod which Tests TestMethod
    – Ewan
    Commented May 16, 2017 at 17:16
  • 1
    @RowlandShaw If an exception is thrown, you see it in the stacktrace, if some intermediate value is wrong you see that when you quickly step through the code. Commented May 16, 2017 at 17:18

2 Answers 2


You should absolutely test this service layer method. Otherwise, how do you know if it works?

Even if you have individual unit tests which guarantee that each of TestMethod1(), TestMethod2() and TestMethod3() works as expected, this does not guarantee TestMethod() works as expected. E.g. it might call the methods in the wrong order, or this set of methods might be be the wrong methods to call in order to fulfill its purpose.

It is sometimes stated that a unit test should only test a single method, but this just refers to a single method at the top level in the unit test. Certainly the tested method might call other methods in turn.


What are you testing? You're testing TestMethod. If the implementation of TestMethod changes, you still want to test this. Your test should be as implementation-independent as possible, so testing this method is important.

My reading tells me that you should only test one method per unit test.

I would suggest you only want to test one invocation/method of your component under test per method, because otherwise your unit test ends up testing a lot, and if your first invocation fails, you won't get a chance to even invoke the subsequent methods. How that method is implemented, however, should be opaque to the test. If you change that implementation in the future, your test should remain the same, and hence confirm your refactoring did not change the behaviour of that method unexpectedly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.