Home » Tag Archives: JUnit

Tag Archives: JUnit

Android Studio 3.0 – Initial Impressions of Tool Support

I have been using Android Studio 3.0 since since the alpha versions, and it is good to see it finally released. This is just some initial comments on using some common and new Android tools and libraries with the 3.0 version of Android Studio and the associated Android Gradle plugin. Hopefully this will be useful for anyone thinking of upgrading ...

Read More »

JUnit 5 meets AssertJ

JUnit 5 brings a lot of improvements in the assertions library, mainly thanks to Java 8 and Lambda Expression support and thanks to the presence of the new assertions like assertAll, assertTimeout orassertThrows. Although I really like JUnit 5 I believe that AssertJ is still a must in production grade unit tests and I will continue using it. But I ...

Read More »

JUnit 5 – Basics

JUnit 5 is the next generation unit testing framework for Java equipped with many interesting features including nested tests, parameterized tests, new extension API or Java 8 support to mentioned a few. This article shows basic concepts of JUnit 5 including test lifecycle, parameter injection and assertions (basic, timeout and exception). Documentation First of all, JUnit 5 documentation is just ...

Read More »

Lifecycle of JUnit 5 Extension Model

JUnit5 final release is around the corner (currently it is M4), and I have started playing with it a bit on how to write extensions. In JUnit5, instead of dealing with Runners, Rules, ClassRules and so on, you’ve got a single Extension API to implement your own extensions. JUnit5 provides several interfaces to hook in its lifecycle. For example you can hook to  Test Instance ...

Read More »

Cleaner parameterized tests with JUnit 5

The general idea of parameterized unit tests is to run the same test method for different data. Creating parameterized tests in JUnit 4 is far from being perfect. There are many issues with the existing architecture: parameters are defined as class fields and constructor is needed to create them, parameterized and non-parameterized tests cannot be mixed in one test class ...

Read More »

Testing exceptions with JUnit 5

JUnit 5 brought pretty awesome improvements and it differs a lot from its predecessor. JUnit 5 requires Java 8 at runtime hence Lambda expressions can be used in tests, especially in assertions. One of those assertions is perfectly suited for testing exceptions. Setup the project To demonstrate JUnit 5 usage I used my long-lived unit-testing-demo Github project as it already ...

Read More »

JUnit 5 – Parameterized Tests

JUnit 5 is pretty impressive, particularly when you look under the covers, at the extension model and the architecture. But on the surface, where tests are written, the development is more evolutionary than revolutionary – is there no killer feature over JUnit 4? Fortunately, there is (at least) one: parameterized tests. JUnit 5 has native support for parameterizing test methods ...

Read More »

Importance of given-when-then in unit tests and TDD

Recently, I’ve been writing rather about more advanced concepts related to automatic testing (mostly related to Spock). However, conducting my testing training I clearly see that very often knowledge of particular tools is not the main problem. Even with Spock it is possible to write bloated and hard-to-maintain test, breaking (or not being aware of) good practices related to writing ...

Read More »