Maven Setup For Testing Java Applications

Starting with a new programming language is always exciting. However, it can be overwhelming as we have to get comfortable with the language, the tools, conventions, and the general development workflow. This holds true for both developing and testing our applications. When testing Java applications with Maven, there are several concepts and conventions to understand:

Read More

Creating Deep Stubs With Mockito to Chain Method Stubbing

Yet another blog post about a Mockito feature that we should rarely use: Mockito deep stubs. With this article, we’ll explore how deep stubbing can reduce the boilerplate stub setup for our tests when chaining fluent APIs of a mocked class. In general, “Every time a mock returns a mock, a fairy dies” should be

Read More

Initialization Strategies With Testcontainers For Integration Tests

Testcontainers offers several initialization strategies for our Docker containers when writing integration tests. Depending on the Docker image we use for our tests, we might have to perform additional setup steps. This includes adjusting the container configuration or populating data. With Testcontainers, we can tweak the container configuration either during runtime (executing commands inside the

Read More

Java AWS Lambda Container Image Support (Complete Guide)

My original plan was to demo the container image support of AWS Lambda with a Java example that uses Selenium to scrape web pages. For Python and Node.js, there are a lot of examples available on the internet. I failed to get Chrome running for a Java AWS Lambda function with a custom Docker image.

Read More

Mock Java Constructors With Mockito | Configuration and Examples

Starting with Mockito version 3.5.0, we can now mock Java constructors with Mockito. This allows us to return a mock from every object construction for testing purposes. Similar to mocking static method calls with Mockito, we can define the scope of when to return a mock from a Java constructor for a particular Java class.

Read More

How to Test Java HTTP Client Usages (e.g. OkHttp, Apache HttpClient)

Fetching data via HTTP from a remote system is a task almost every application has to solve. Fortunately, there are mature Java HTTP client libraries available that are robust and have a user-friendly API. Most of the frameworks ship their own HTTP client (e.g Spring with WebClient and RestTemplate, Jakarta EE with the JAX-RS Client),

Read More

Write Concise Web Tests With Selenide for Java Projects

Good old web tests – extremely valuable but annoying once they get flaky. If you are familiar with Selenium, you might find your self-writing helper functions to e.g., wait on elements to be present in the DOM, or AJAX calls to finish. As Selenium is more or less a low-level API to manage the browser,

Read More

Mocking Static Methods with Mockito (Java & Kotlin)

Want to start a religious discussion? Start asking your teammates whether or not you should mock static method calls. It’s debatable if this is an absolute no-go or sometimes a last resort. I agree that you should rethink your implementation if you find yourself googling: Mocking static calls Java. On the other side, there are

Read More

Five JUnit 5 Features You Might Not Know Yet

Writing your first test with JUnit 5 is straightforward. Annotate your test method with @Test and verify the result using assertions. Apart from the basic testing functionality of JUnit 5, there are some features you might not have heard about (yet). Discover five JUnit 5 features I found useful while working with JUnit 5: test

Read More

Java AWS Lambda Example with Serverless and Maven

With this blog post, you’ll learn how to use the Serverless framework to develop AWS Lambda functions using Java and Maven. To provide you with a realistic use case, we’ll develop an AWS Lambda that will generate a thumbnail for each new image that we upload to an S3 bucket. AWS Account Setup for Serverless

Read More