Sunday, May 24, 2020

Moving to JUnit 5

JUnit 5 has been available for several years now. Yet I've seen and heard from many organizations that stubbornly stick with JUnit 4. Yes, it meets their needs, but if they were to make the leap to JUnit 5, they would benefit from all the great new features. And it's not that hard to move forward.

I've attempted to provide a bit of encouragement in the form of a new e-book, "Moving to JUnit 5: Migrating and Using the New Features". It's a breezy guide in two parts:
  1. Moving from earlier versions of JUnit to JUnit 5.
  2. Learning the new JUnit 5 features.
The complete book description is below. I hope you will check it out!

Looking to migrate from JUnit 4 to JUnit 5? Need a quick introduction to new JUnit 5 features?

JUnit 5 brings exciting features and unlocks new styles for writing unit test code in Java. But many projects are still using earlier versions of JUnit and struggling with the decision to move forward. This book will help you make your move to JUnit 5 in two steps:

•Migrating from older versions of JUnit.
•Taking full advantage of JUnit 5.

In the first half of the book, we discuss gradual migration, new annotations, changes to commonly used assertions, and replacing runners and rules with extensions. In the second half, we cover new JUnit 5 features like grouping of assertions, nesting test cases, writing conditional test cases, injecting parameters, and more.

At the end of the book, you will know everything you need to know to confidently move to JUnit 5 and write more modern and fun unit tests.

Saturday, April 25, 2020

New Book Alert: Microservices Testing in Brief: Using Hoverfly, Pact, and Containers

Recently, I published another book in the Kindle Store, and I wanted to draw your attention to it because if you're doing microservices, I think it can really help you out.

It's called "Microservices Testing in Brief: Using Hoverfly, Pact, and Containers". The material is based on some well-received training I taught in Beijing about a year ago. Here is the description:

Modern software systems are increasingly built using a microservices architecture, where functionality is broken down into many small servers that connect over remote procedure calls. Microservices bring lots of benefits in terms of scalability and development team agility.

But microservices can also complicate the testing process. Fortunately, new tools and approaches are available to tackle these challenges.

In this hands-on book, we will get a brief introduction to:

•Unit testing using API simulation and Hoverfly.
•Integration testing with consumer-driven contracts and Pact.
•System testing with a test container in Docker.

At the end of the book, readers will have a solid foundation for introducing these testing techniques in their microservices environments.

Check it out and let me know what you think!

Saturday, April 11, 2020

Published "Mock Object Testing with Examples Using Mockito"

I just published my latest e-book, "Mock Object Testing with Examples Using Mockito" in the Kindle Store.

The focus of the book is on testing with mock objects in general, rather than a detailed guide to any specific framework. But I had some requests to rework my previous book, "Mock Object Testing with Examples Using EasyMock", to use Mockito. So here you go!


Mock objects are a powerful tool for unit testing in complex modern software systems. But mock object testing is also misunderstood by many developers who struggle to use mocks to create elegant, maintainable tests.

Using the popular Mockito framework for Java, this book reveals mock object testing across the entire expect-use-verify cycle. Topics include:
•Dependencies and Testable Design
•Creating a Mock from Scratch
•Nice and Strict Mocks
•Setting Expectations
•Mock Method Results
•Partial and Class Mocking

At the end of the book, readers will have a solid grasp on everything that can be done with mocks and be well-prepared to introduce mock object testing into their own unit tests.

Check it out, leave a review, and let me know what you think!

My new weekend project is a short guide to microservices testing based on some training I gave last year. Stay tuned for more news on that.

Sunday, March 29, 2020

HAR Sanitizer in DockerHub

HAR (HTTP Archive) files are a really useful troubleshooting tool for browser developers: You can take a HAR file from an end-user or tester, load it up in the Chrome debugger, and see the request and response data in the Network panel as though you replayed the scenario yourself. This is particularly helpful in debugging, 403's, 404's, and performance issues (among others).

There's a catch, though: HAR files contain sensitive information like auth headers, cookies, and other personal data. As a web developer, users should not be sending these to you, and you should not be attaching them to (say) JIRA issues.

To help with this problem, Google released an unofficial open source application called HAR Sanitizer. It allows you to upload a HAR file from which it will automatically strip well-known sensitive information (think: certain auth cookies) as well as any other fields you choose. The resulting "sanitized" HAR file is then theoretically safe to share with developers.

If you'd like to try it out, there's a live version running on AppSpot.

That said, I'm always a little bit nervous asking my users to upload sensitive information to a third-party website, even if it does appear to be one unofficially supported by Google. What if I could get them to run HAR Sanitizer on their local machines instead?

If you happend to look at the HAR Sanitizer installation instructions on Github, you might have noticed they are a little complicated. Probably not something I could explain to most users how to do.

But I DO think I can explain to most users (at least in-house users) how to run a Docker image. That's why I packaged up HAR Sanitizer and uploaded it to Docker Hub.

The image build code is here.

The image itself is here.

Let me know if you find this useful.

Monday, October 21, 2019

Reading Company Engineering Blogs to Prepare for System Design Interviews

We've all been there, writing code on a whiteboard to solve algorithmic puzzles in tech interviews. These days, though, more interviewers and companies are recognizing the limitations of this interviewing style, particularly for mid-career and senior engineers: If you've been successfully building real-world systems but your last algorithms class was years or even a decade or more ago, inverting a binary tree (my personal favorite question to ridicule) may not be the best indicator of your skills.

Consequently, a question I get a lot deals with how to prepare for system design interviews. Traditional tech interview prep tools (think: Leetcode) are extremely weak in this area. But all is not lost. Indeed, many of the most-admired tech companies have lively engineering blogs where engineers describe how the real-world systems you use every day are built, and this is exactly the knowledge you need to succeed in an interview setting. And as an added bonus, unlike Leetcoding your life away, the time you spend studying system design translates directly into your day-to-day work.

Without further ado, allow me to list some of my favorite company engineering blogs, along with a hand-picked example post to get you on your way to tech interviewing success:

AirBnb: Avoiding Double Payments in a Distributed Payments System -- the benefits of idempotency in a microservices architecture and how to achieve them is a great interview question.

Facebook: Scribe: Transporting petabytes per hour via a distributed, buffered queueing system -- since we're all familiar with logging, log data collection is a ripe target in an interview.

Lyft: Building Lyft’s Marketing Automation Platform -- this one is just near-and-dear to my heart as someone who has worked in the domain.

Netflix: How Netflix microservices tackle dataset pub-sub -- Netflix is the gold standard for sharing details (and open source) of their innovative modern microservices architecture. Every minute you spend on their blog is time well spent.

Twitter: Dynamic configuration at Twitter -- hot reloading, feature switches, A/B testing support, etc.

Uber: Using GraphQL to Improve Data Hydration in our Customer Care Platform and Beyond -- build an efficient frontend to a microservices backend with GraphQL.

Best of luck to you!