Disclaimer: This post is highly opinionated!

Here are my top favourite tools for testing in java:

Mockito

Mockito seems to be the de-facto standard for creating mock objects in java and is imho far better than easymock.

Some hints:

  • I prefer using the BDD mockito style. I like to structure my tests in given-when-then blocks. When I write when(mock.method()).thenReturn(value) I always get confused in my head because I’m still in the “given” block. So I prefer the given(mock.method()).willReturn(value) style more.
  • I like to populate an object under test with only one line of code.

Selenium / WebDriver

Selenium is the de-facto standard for testing web applications.

Testcontainers

Need a database for your tests? Need a browser for your selenium tests? Use testcontainers and easily set up everything without headache.

Some hints for its usage can be found on one of my former blog posts.

WireMock

You need to fake some remote http service? Here comes wiremock!

AssertJ

I already liked to work with fest assertions. Now my favourite is AssertJ.

  • fluent API
  • API is close to natural language
  • API is easy to autocomplete in your IDE
  • You do not always confuse “actual” and “expected” values.

EasyRandom

You have some value object, that should be used in a test, but its values are not important? Use EasyRandom to populate it with some random values.

TestNG

Working with JUnit 5 is ok, but TestNG is far more better.

TestNG has good parameterized tests (“DataProvider”) since more than ten years. TestNG’s concept of suites is far more mature than JUnit’s tags. In JUnit I sometimes need to write static initializers for some test setup. TestNG is far more flexible here.

Any comments or suggestions? Leave an issue or a pull request!