1. This guide is simply Awesome! Thanks for such great work explaining all the options to test controllers and differences between them. :+1

  2. I really appreciate the depth of this article! Thanks

  3. Excellent article! The best article I’ve found about testing springboot

  4. Regarding the Standalone approach, do you have an example where given willReturn a List? I am having problems making this work and cannot find good documentation. I know this article is a year old but I would appreciate any help. Thanks.

    1. Author

      I wrote another post recently focused on BDD Mockito and assertions with AssertJ in which I use examples of given(someMethod).willReturn(list):
      BDD Unit Tests with BDDMockito and AssertJ
      If that doesn’t solve your question, just point me to your code (GitHub for example) and I can have a look.

  5. I am basically trying to do the same thing as canRetrieveByNameWhenExists() but instead of returning a single object my controller method returns a List. The response returns a 200 but the content is empty. If I remove the given statement and the 2nd assert, the test passes. I’m wondering why this doesn’t work the same as a method that returns a single object?

  6. Author

    I don’t think that the problem is related to returning a list instead of a single object. It’s difficult to analyze what’s exactly going on there without the whole context, but you can try replacing your given statement by

    just to discard problems related to equality checks of mock methods.