DEV Community

10 Essential Testing Frameworks & Libraries for Java Programmers

javinpaul on April 09, 2019

Disclosure: This post includes affiliate links; I may receive compensation if you purchase products or services from the different links provided i...
Collapse
 
stealthmusic profile image
Jan Wedel • Edited

Hi, good list of useful tools. One thing you seem to have missed is AssertJ as an alternative assertion library. It’s fluent API is much more readable and versatile than the standard JUnit assertions. I also think it ships as a transitive dependency with spring testing. So you just need to static import the right methods. I’ve never looked back. 😊

Collapse
 
javinpaul profile image
javinpaul

Thanks for suggestion, is it better than Hamcrest? another similar library which provides fluent assertion methods to read your test like English.

Collapse
 
stealthmusic profile image
Jan Wedel

Hey, no, Hamcrest is a Matcher Library, AssertJ is an assertion Library, that actually supports Hamcrest matchers and I’m using them as well. It’s a bit complicated... 🤪

Thread Thread
 
javinpaul profile image
javinpaul

Ah I see, I am sure going to try that on my unit tests now. How about mocking, do you use Mockito or PowerMock? I am a big mockito fan but I always stuck with mocking static fields like Logger in some Java classes.

Thread Thread
 
stealthmusic profile image
Jan Wedel

Definitely Mockito. If you need to use PowerMock you’re probably doing something wrong. Why would you ever need to mock the logger?

Collapse
 
beatngu1101 profile image
Daniel Kraus

Great article! 👍

You may also want to check out recheck-web (disclaimer: I'm a contributor). It is a library for Golden Master Testing of web apps, respectively, their UIs, which replaces traditional assertions.

(Also happy to get your feedback.)

Collapse
 
javinpaul profile image
javinpaul

Nice one @daniel , will take a look, does it complements Selenium or alternative of that?

Collapse
 
beatngu1101 profile image
Daniel Kraus

It complements Selenium in terms of assertions and locators. Oh, and did I mention it is open source? 😊

Thread Thread
 
javinpaul profile image
javinpaul

That's awesome, it's now on my TODO list to check :-) Once again thanks for suggesting it.

Collapse
 
sixman9 profile image
Richard Joseph

From what little I've seen, the executable Cumcumber/Gherkin style API testing specifications of the Karate testing framework (by Intuit, of 'Quickbooks' fame) look amazing, actually. Quoting them:

If you are familiar with Cucumber / Gherkin, the big difference here is that you don’t need to write extra “glue” code or Java “step definitions” !

The idea is, you use a VERY extended Gherkin syntax (Given-When-Then) specification definition to avoid having to write test code (although Karate does integrate with JUnit, so as to be runnable from an IDE etc.). This means that non-programmers and product owners can concretely define JSON/XML-based payloads, specify endpoint URL's, HTTP verbs and write test validation matchers, again interrogating JSON/XML/etc. return types, all from the specification script, thus:

Feature: simple example of a karate test => https://github.com/intuit/karate/blob/master/karate-netty/src/test/java/com/intuit/karate/mock/hello-world.feature

Background:
# to test that expressions also work for the method keyword
* def postMethod = 'post'
* def getMethod = 'get'

Scenario: create and retrieve a cat

Given url mockServerUrl + 'cats'
And request { name: 'Billie' }
When method postMethod
Then status 201
And match response == { id: '#ignore', name: 'Billie' }
# And assert responseTime < 1000

Given path response.id
When method getMethod
Then status 200
Collapse
 
s1hofmann profile image
Simon Hofmann

Nice collection of testing tools!

May I suggest an addition to your list?

You might want to take a look at Citrus, an integration testing framework for various message protocols and data formats.
It supports HTTP REST, JMS, Kafka, SOAP, FTP, SSH, XML, JSON and much more, so it's possible to test you application / microservice fully isolated!

Collapse
 
javinpaul profile image
javinpaul

Thank you @Simon Hofmann, I'll sure take a look, looks intereting :-)

Collapse
 
spqrbob profile image
Bob McCann

Nice article! Thank you very much for the good test info!

Collapse
 
javinpaul profile image
javinpaul

your welcome @bob , thanks for your comment.