Maven: Use JUnit 5 with Spring Boot for unit and integration tests

Last weekend, a new version of the Apache Maven Surefire-Plugin has been released:

The Failsafe-Plugin has been updated as well. Both support JUnit 5 natively.

To make use of JUnit 5 in a Spring Boot 2 application, there’s not much todo. Here’s a gist of a POM that brings everything. See comments in the code. Basically all you have to do is overwrite the managed versions of the Surefire- and Failsafe-Plugins and then exclude the JUnit 4 dependency from Spring Boots Starter Test (and all other test related starters, i.e. security-starter-test). You’ll than declare both the JUnit 5 Jupiter Api and Engine, both in scope test. You could put the engine into the plugins dependency, but I couldn’t think of an aspect that’s improved by more cruft. Then, write unit and integration tests as shown (the later with annotated with @ExtendWith(SpringExtension.class)).

You’ll notice that only the Failsafe-Plugin has been declared. Spring Boots parent POM already takes care of the Surefire-Plugin.

And that’s all you need for Spring Boot 2 with JUnit 5.

| Comments (0) »

18-Jun-18


Some thoughts about Effective Java, Third Edition and general musings

Lately, German publisher dpunkt.verlag reached out to me wether I’d think it’s a good idea translating Joshua Blochs Effective Java 3rd edition (Partnerlink) to German. Effective Java has been on my Good reads list for a while now and I read the first edition in 2003 or 2004, don’t remember exactly when. I hopefully learned a thing or two in that time and sadly seen some things better left unseen and my initial thought was: Go for it! If a translated version helps spreading best practices and especially things one should not do, it’s worth the effort.

To my surprise, dpunkt than asked if I could review the translation. And so it happened that I read the third edition in its total, mostly parallel in German and English:

My friend Thorben has reviewed the book already very concise at his Thoughts on Java blog. I fully agree with him.

One thing I have to quote is Joshua Bloch himself:

If you have ever studied a second language yourself and then tried to use it outside the classroom, you know that there are three things you must master: how the language is structured (grammar), how to name things you want to talk about (vocabulary), and the customary and effective ways to say everyday things (usage). Too often only the first two are covered in the classroom, and you find native speakers constantly suppressing their laughter as you try to make yourself understood.

This is from the foreword itself and is basically the essence of the book.

If one gets the idea on how to start a Java program, the weird notion of the main-method and have an idea about objects, Java does not have a step learning curve. One can solve many problems without going deeper into the specifications or fully understanding what’s happening behind the scenes.

Most of the time, stuff works out, some times not. Usually those times happen to be late in the evening, on a weekend duty etc. Performance optimizations that should not have been done. Cloneable or serializable classes that violates their invariants. And many more.

Effective Java does address all these and more.

It also is written from an API creators point of view as one clearly sees on how Joshua stresses good documentation at the API level.

One does wonder if qualities being important for an API are equally important for a product or a software that has it’s value in the business it powers? I’d say yes. There’s always a team that has to maintain code or hast to fix bugs. Add new features. I don’t believe in a permanent rewrite of (micro)services. By all probability, the Netflixes, Amazons and Googles of this world do this, but at least I have not yet been in a project where that was a legitimate thing.

Given that premise, I’d rather build my stuff on a solid fundament and that starts with some best practices and at least the ambition to learn a language a bit deeper than just on the surface.

Funny enough, my tweet about Lombok did gain some traction:

I like the project but use it very selectively, most of the time @Getter, @Setter, @EqualsAndHashCode (that one only with the of-attribute) and sometimes @Builder. I use it to create immutable, small values classes with not more than 4 or 5 fields and @RequiredArgsContructor. I’m probably even the last person who learned yesterday, that there is @Synchronized, but at least I can explain what and why the stuff that @Synchronized does, is actually a good idea. If one has a library like Lombok or Googles AutoValue in a project, an understanding of Javas details become paramount or otherwise all kinds of interesting things can happen (if we speak on a higher level like Michael @bitboss Plöd argues, inflationary generation of accessors defies information hiding and encapsulation and should be avoided).

If you want to master the language Java, read all items in the book. If you’re more into other (JVM) languages as well, the chapters General programming, Exceptions and Concurrency have value without Java, too (By the way, you should sometimes have a look at other languages. Kotlin is nice and Simon has a great blog. However it might be a good idea to really look outside the OO box and take a sneak peek at Clojure).

tl;dr: I firmly believe that one has not to master every detail of a day-to-day language but one should know more than just the basics and to the right things the right way. Effective Java has some more or less controversial items, but overall, it indeed helps to be more effective.

| Comments (0) »

08-Jun-18


May 2018: Interviews, Spring I/O and more

Hard to believe, May is already gone. The month was pretty though for me, it startet with a bike crash for me, that cost me a bike and some time at the doctors.

Interviews and articles

I was very happy about publications at Heise Developer. First of all there has been a recap about JavaLand 2018 and the mentoring program in which I took part: Die jungen Wilden pt. 2.

Next was an interview conducted by Thorben Janssen with me, also for Heise Developer: Im Gespräch: Michael Simons über Spring Boot 2 und sein neues Buch. Thanks a lot for that, Thorben!

There was another interview I did during JAX last month with the JAXenter: Michael Simons über Softwarearchitektur. My series of articles about Spring Boot 2 has been translated to English for the international version of JAXenter as well: part 1, part 2, part 3 and part 4.

And last but not least, I wrote a piece for Informatik Aktuell about 4 years of Spring Boot: 4 Jahre Spring Boot.

My book is available on Amazon, as paperback and Kindle-Edition.

Spring I/O 2018

I did travel a lot in May, some holiday, but also work. I was at Spring I/O again, this time with a session about Micrometer:

Micrometer and metrics are a super interesting topic. I put a lot of effort into this talk and into the demo. To my personal disappointment, I delivered the talk not as good as I wished. The month with it’s bad start and the traveling took a bigger toll on me than expected. Anyway. I tried something new and published my personal transcribed for the talk as well, find it here. The sources for the demo are – as always – on GitHub.

| Comments (0) »

28-May-18


April recap: JAX 2018 and having a bestselling book on Amazon

We’re only in for 4 months in 2018 and I can not believe all the stuff already happened. I did one final iteration of my talk about Spring Boot starters at JUG Saxony in Leipzig. It was their 100th meet up and the welcomed me with great hospitality. I was very happy to meet my friend Oliver there. Just a day later, several colleagues from INNOQ and I met at our Berlin office for a workshop about cherishing communication by Spring Boot Book started to appear in physical form on Amazon and other shops just in time for JAX.

My colleagues Martin and Simon at the booth:


Thanks a lot to Ralf for helping us with the booth. Also for challenging me with a complicated topic which should be way more simple:

I had a fresh new talk with Michael Plöd about Spring Boot 2 hot topics on a ridiculously large stage:


The talk went very well and spiked the sales of the book a lot, resulting in this:


I’m actually a bit overwhelmed. The book hitting place #478 in all German books by the end of Thursday was a blast. Thank you kind people out there for supporting me. Keep sending me all those unwrapping pictures, I’m already looking forward to your feedback. Maybe in form of a review?

JAX itself ended for me coaching in an architecture retreat with Susanne, Peter, Jörg and Eberhard. It started a bit out of my comfort zone but it was a good thing todo.

Back to the book:

Analysing a book

The following content is a Jupyter notebook. It’s an embedded Gist. You can clone it and use it as a base for your own experiments.

| Comments (0) »

28-Apr-18


March 2018 recap

March 2018 was a damn crazy month. It began with the release of Spring Boot 2.0 which meant big congratulations to the whole Spring Boot team and more work on my side: I’ve updated all examples for the Spring Boot Buch, went through the manuscript one last time and sent it to my publisher. I’ve written the book with LaTeX, using Minted and Pygments for syntax highlighting and I think the people at DA-TEX did a stellar job for the final typesetting:



Also thanks to René Schönfeldt at dpunkt for your support during the last year and getting that thing to the printing plant in March. Also many thanks to Eberhard Wolff. He helped me with valuable feedback and mentoring throughout the last year. The book should hit stores any time soon now. You may get it at Amazon or an ePub version at dpunkt plus.

Dating back to November of last year, Dominik asked me to write about Spring Boot 2 for JAXenter. Those articles came out in March, too:

Those post are German but are being translated for the english portal as well at the moment. I’m quite impressed how many rubber boot pictures are out there.

And then there was JavaLand 2018. I have been to every installment of JavaLand, have been involved two times in the program committee, spent last year as a mentor at JavaLand4Kids and this year, I could be a mentor for my friend Felix who spoke about generating tests in the newcomer track in the fully booked tent:



Thanks a lot for putting your trust in me, Felix! Inspired by the success we had and Timothées talk about mentoring, I’d love to do that again.

I myself feel blessed and lucky. 2 years ago, I was invited to speak at Spring I/O 2016 about Spring Boot starter. First public talk ever and from there on the ride got a bit crazy. 15 more talks leading to this audience at JavaLand and I’m still totally stocked:



Thank for being there!

Last but not least: Several services I worked on the last 3 months went into production. One based on a mix of Jersey/JAX-RS/HK2, two Spring Boot based. I’m totally thrilled how easy one could integrate Spring Boot with just a few starters into a foreign ecosystem.
The team basically could still write JAX-RS-Resources as used too and enjoying all the good stuff that comes with the Spring ecosystem, mainly Spring Data repositories and especially Spring Integration. Incredible how easy and clean flows can be defined by the Java-DSL. I was asked what the advantage of Spring Boot was for the new services compared to the old stack: Even though I had to write some integration points, we could work on a much faster pace, having to deal a lot less with plumbing code and concentrate on the business value.

April will start with vacation for me and hopefully, I’ll finally hold a copy of my book in my hands during the next days.

| Comments (0) »

31-Mar-18