Clean Integration Testing with JUnit Rules
The benefits of JUnit Rules, especially when dealing with integration testing, can hardly be overrated. In this post, we’ll shine a light on the usefulness of ExternalResource extensions. These simplify fixture control in cases where we have to work with external-resource-abstracting third-party libraries. As an example, we’ll have a look…
Lightweight Integration Tests for Eclipse Extensions
Recently I introduced a little helper for Eclipse extension point evaluation. The auxiliary strives to reduce boilerplate code for common programming steps, while increasing development guidance and readability at the same time. This post is the promised follow-up that shows how to combine the utility with an AssertJ custom assert…
Clean Unit Test Patterns – Presentation Slides
I was given the opportunity to talk at the GDG DevFestKarlsruhe 2014 conference about ‘Clean Unit Test Patterns’. Thanks to the organizers for inviting me and thanks to all people listening to my talk. As promised I shared the presentation e.g. for those who want to have a look at…
JUnit in a Nutshell: Yet Another JUnit Tutorial
Why Another JUnit Tutorial? JUnit seems to be the most popular testing tool for developers within the Java world. So it is no wonder that there have been written some good books about this topic. But I still meet quite often programmers, who at most have a vague understanding of…
JUnit in a Nutshell: Unit Test Assertion
The last chapter of my multi-part tutorial about JUnit essentials covers various unit test assertion techniques. It elaborates on the pros and cons of the built-in mechanism, Hamcrest matchers and AssertJ assertions. The ongoing example enlarges upon the subject and shows how to create and use custom matchers/assertions. Unit Test…
JUnit in a Nutshell: Test Runners
The fourth chapter of my multi-part tutorial about JUnit testing essentials explains the purpose of the tool’s exchangable test runners architecture and introduces some of the available implementations. The ongoing example enlarges upon the subject by going through the different possibilities of writting parameterized tests. Since I have already published…
JUnit in a Nutshell: Test Isolation
Chapter three of my multi-part tutorial about JUnit essentials discusses the implications of unit dependencies for testing. The post illustrates the test isolation principle and shows how it can be put into practice – based on the nomenclature defined by Meszaros in xUnit Test Patterns [MES]. The ongoing example continues…
JUnit in a Nutshell: Test Structure
Chapter two of my multi-part tutorial about JUnit testing essentials will continue the ongoing example and work out the common structure that charactarizes well written unit tests. The nomenclature used throughout this post was defined by Meszaros in xUnit Test Patterns [MES]. The Four Phases of a Test The tutorial’s…
JUnit in a Nutshell: Hello World
JUnit in a Nutshell is a multi-part tutorial about the essentials of JUnit testing. This Hello World chapter introduces the very basics of a test: how it is written, executed and evaluated. The post also kicks off the ongoing example, which is continuously carried forward throughout this mini-series. Why bother?…
Clean JUnit Throwable-Tests with Java 8 Lambdas
Recently I was involved in a short online discussion on twitter and google+ which concerned the question why the arrival of Java 8 Lambda expressions makes the catch-exception library1 obsolete. This was triggered by a brief announcement that the library won’t be longer maintained as lambdas will make it redundant….
A JUnit Rule to Run a Test in Its Own Thread
In JUnit it could be occasionally helpful to run a test in its own thread. In particular when writing integration tests that interact with encapsulated ThreadLocals or the like this could come in handy. A separate thread would implicitly ensure that the thread related reference of the threadlocal is uninitialized…
Clean Synchronization Using ReentrantLock and Lambdas
Recently I was reading an informative post about the differences between synchronized vs ReentrantLock by Javin Paul1. He emphasises on the advantages of the latter, but does not withhold some downsides, which are related to the cumbersome try-finally block needed for proper usage. While agreeing with his statements I brooded…
Efficient Code Coverage with Eclipse
There is a saying that a fool with a tool is still a fool. But how to use a tool most efficiently is not always obvious to me. Because of this I typically spend some time to check out new playgrounds1 that promise to increase my work speed without impairing…
What are Mockito Extra Interfaces?
Mockito is my favored little helper if it comes down to write light weight JUnit tests. It is very useful to replace the ‘real’ dependencies of a unit under test easily by mocks if necessary. In particular when working on the borderline to framework APIs such dependencies can otherwise be…
Getting JUnit Test Names Right
Finding good names is one of the challenges of crafting software. And you need to find them all the time and for everything – classes, methods, variables, just to name a few. But what makes a name a good name? To quote Uncle Bob: ‘Three things: Readability, readability, and readability!’…
Clean SWT Listener Notifcations with SWTEventHelper
Writing tests for SWT based UIs often requires to notify widget listeners programmatically. Unfortunately, the code to create, initialize and finally to trigger the event is a bit verbose and distracts from the actual purpose of the test. After writing similar initialization routines a couple of times I came up…
A JUnit Rule to Ease SWT Test Setup
Rüdiger and I have written a lot of SWT test cases for our current RCP project lately. Most of the time we can execute them as plain JUnit tests. Still they also have to run in a RCP integration environment. Long story short we wrote a DisplayHelper fixture to reduce…
Mockito Templates for Eclipse
Sometimes I miss the forest for the trees – and that for a disturbingly long time. I just became aware of this once again recently, typing one of the more verbose mockito expressions for the umpteenth time. The statement in question was a doAnswer(Answer) construct which always feels a bit…
More Units with MoreUnit
Just over a year ago I wrote a post about working with JUnit in Eclipse. One of the commenters recommended MoreUnit in order to increase testing efficiency even more. Giving it a try I was delighted and the plugin’s keyboard shortcuts were immediately memorized by my autonomic nervous system… Additionally,…
A JUnit Rule to Conditionally Ignore Tests
I always believed that using @Ignore to deactivate tests is a bad idea. Except, maybe as one way to put tests that fail intermittently into quarantine to attend to them later (as Martin Fowler describes it here). This bears the danger that the test suite decays as more and more…