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:
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
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
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.
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.
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),
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,
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
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
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