0

I am trying to write a unit test case for android using Junit-5 and mockito But how to write test case for this kind of function when there is a return statment

```public void doSomething() {
        if (isTrue()) {
            return;
        }
        some other code 
}```

1 Answers1

0

As the return type of your method is void, you can only test behavior and not the state.

If your method is coordinating the invocation of other methods on other objects (collaborators), you can use Mockito to verify that the interaction with another (mocked) object happened.

In case there's an early return in your method, you could ensure the invocation did not happen.

Here are some further reads that might help:

rieckpil
  • 10,470
  • 3
  • 32
  • 56