I think that software development is more than just a job. I see myself as an artisan who is trying to get better every day. The “easiest way” to do this is to find a few good tools and find the answers to these questions:

When should I use the tool X?

How should I use the tool X?

Automated testing is a very important part of software development, but I haven’t seen a lot of blog posts that let you to take a peek into the toolbox of another developers.

This blog post lets you to take a peek into my toolbox. I will reveal 12 tools that I use for writing unit and integration tests. I will also provide links to other interesting webpages that help you to understand how you can use them.

Let’s get started.

Taking a Peek Into My Toolbox

Before we can use the tools that are described in this blog post, we have to create a build that can run both unit and integration tests. I have written two blog posts that describe how we can do this:

Integration Testing with Maven describes how we can create a Maven build that has different directories for unit and integration tests.

Getting Started With Gradle: Integration Testing With the TestSets Plugin describes how we can create a Gradle build that has different directories for unit and integration tests.

We are now ready to take closer look at my toolbox. I have divided my tools into different categories that makes this blog post easier to read.

I give you 12 tools that I use for writing unit and integration tests:

Running Tests

JUnit is a framework that I use for writing both unit and integration tests. I like JUnit because it is the most popular testing framework for Java programming language. In other words, it has a lot extensions and it is easy to find solutions to your problems.

NestedRunner is a JUnit runner that allows us to run test methods placed in nested inner classes. I like NestedRunner because of the following reasons:

We can replace long method names with BDD style class hierarchy.

We can remove duplicate code by moving that code to setup methods and putting these methods to the correct inner classes.

We can link the constants with the test cases that use them by declaring the constants in the correct inner class.

junit-dataprovider is a JUnit runner that allows us to write parametrized tests by using a TestNG like data provider. This is a huge improvement over the default way of writing parametrized tests that pretty much sucks.

Additional Reading:

Mocking, Stubbing, and Faking Stuff

Mockito is the most popular mocking framework for writing unit tests. I like it because it has a simple API, a lot of useful features, and excellent documentation.

Greenmail is an in-memory email server that supports SMTP, POP3, and IMAP with SSL socket support. I like it because it is really easy to use. When I was looking for a “fake” email server, I tried several alternatives and Greenmail was the only one that worked as I wanted.

MockFtpServer is a library that provides two different FTP server implementations (fake/stub) that are useful for testing different scenarios. If we need test code that interacts with a FTP server, MockFtpServer is our weapon of choice.

Additional Reading:

Writing Assertions

Hamcrest provides matchers that we can use to write assertions for our unit and integration tests. I use it when I need to write assertions for unit or integration tests that use the Spring MVC Test framework.

AssertJ provides a fluent API for writing assertions that have helpful error messages. It improves the readability of our test code and helps us to transform our test cases into executable specifications that speak the correct domain-specific language.

Additional Reading:

Testing Data Access Code

H2 is a very fast in-memory database that is useful for writing integration tests that are run in the local development environment.

DbUnit is a JUnit extension that can be used to initialize the database into a known state before each integration test and ensure that the database contains the correct data. DbUnit has its warts, but it is a very useful tool because it helps us to separate the test data creation from the tested code.

Additional Reading:

DbUnit Core Components describes the core components of DbUnit. If we want to write tests that use DbUnit, we should know what these components are.

DbUnit Best Practices provides five rules that help us to write better tests for our data access code.

Writing Tests for Data Access Code helps us to write deterministic data access tests which test the right thing, are easy to read, and easy to maintain.

Testing Spring Applications

Spring Test is the Swiss army knife of writing automated tests to Spring applications. It provides a first class support for writing unit and integration tests to Spring powered applications.

Spring Test DbUnit integrates DbUnit with the Spring Test Framework. If we need to write data access tests for a Spring application that uses relational database, Spring Test DbUnit helps us to do it.

Additional Reading:

If you want to learn how I use these tools for writing unit, integration, and end-to-end tests for Spring web applications, take a look at my upcoming Test With Spring Course

What Testing Tools Do You Use?

I have now revealed the tools that I use for writing unit and integration tests. I challenge you to do the same. You can participate in this challenge by following these simple steps:

If you have a blog, you can write a blog post and leave a comment to this blog post.

If you don’t have a blog, you can leave a comment to this blog post.

Why should you do this?

Well, if helping other people isn’t enough for you, I promise to help you to get more readers by linking to your blog post, tweeting it, and sharing it with the Java Testing Society.