Earlier I’ve published a blog post on now to create a RESTful Web Service(JAX-RS) to accept JSON payload with user profile details and how to save user profile details into a MySQL database using Java Hibernate framework. In this blog post I am going to share with you how to test(using JUnit and Mockito) it’s Service…
Read More Test RESTful Web Service with JUnit and Mockito
In this tutorial, you will learn about Spring Bean Scopes, an important part of the Spring Framework. You will learn what they are, how they work, and when to use them. By the end, you’ll have a clear understanding of Spring Bean Scopes, helping you build better Spring applications. Introduction to Spring Beans In the…
Read More A Guide to Spring Bean Scopes
When we do integration testing of our Spring Boot application, we sometimes need to make it load an alternative configuration. For example, we might need to run and test our application on a different port number, make it connect to a database as a different user or even make it connect to a different database.…
Read More @TestPropertySource Annotation Example
This tutorial will guide you through the process of running Unit Tests and Integration Tests separately in a Maven-based Spring Boot application. We will use the JUnit Tag feature to group our test cases and separate Unit Tests from Integration Tests. To learn more, check out the Test Java code tutorials page. Create your tests…
Read More Running Unit Tests and Integration Tests Separately in Spring Boot
If you’re an absolute beginner looking to learn about integration testing for Spring Boot applications with a MySQL database server, then you’re in the right place. As you proceed through this tutorial, remember that everyone was once a beginner, and the only silly question is the one you don’t ask. This tutorial aims to introduce…
Read More Integration Testing with Spring Boot, MySQL and Testcontainers
Testing is an essential skill for any Java developer. It helps you ensure the quality and reliability of your code, as well as find and fix bugs faster. On this page, you will find a collection of tutorials that will teach you how to test Java code using JUnit 5 and Mockito. JUnit 5 is…
Read More Testing Java Code
Mocking a static or private method is often necessary when writing unit tests. However, before Mockito 3.4.0, it was impossible to explicitly mock static methods. Thus, PowerMock offers solutions to the defined use case. In this article, we will look at the introduction of PowerMock and explore examples of mocking private, static, and final methods.…
Read More A Guide to Mocking Private and Static Methods Using PowerMock
Method security testing is the process of testing the security of each method to make sure that only authorized users can access them. By testing the method-level security, we can ensure that our application is secure and that users can only perform the actions that they are authorized to do. Let’s say we built an…
Read More Testing Method Security in Spring Boot
In this REST Assured tutorial, I will demonstrate how to evaluate the JSON content that is returned in the response body of an HTTP response. What is REST Assured? REST Assured is a Java-based library for testing RESTful web services. It provides a domain-specific language (DSL) for writing tests that interact with web services using…
Read More Validate JSON Response with REST Assured
This short REST Assured tutorial will teach you how to validate the HTTP Response Status Code while testing a RESTful Web Service endpoint. Each HTTP Response includes a status code, and by examining the status code value, we can determine if the HTTP Response was successful or not. Let’s explore how we can use REST…
Read More Validate HTTP Status Code: RestAssured
In order to simulate the behaviour of any argument of the specified type during unit testing, we can utilize Mockito argument matchers. In this tutorial, we’ll discuss an Introduction to the Mockito Argument Matchers along with some examples and the creation of a custom argument matcher. So, let’s begin! If you are not familiar with…
Read More Mockito Argument Matchers: Examples and Usage
In the software development process, testing is essential. There are two types of testing i.e. unit testing and integration testing. While unit testing focuses on testing the smallest component of an application, integration testing focuses on testing the end-to-end behavior of the application also known as endpoint testing. Integration testing verifies the @Controller and @RestController…
Read More Testing Spring Boot Applications with MockMvc
In this tutorial, you will learn how to use @MockBean annotation in your Unit tests. @MockBean annotation is used to create and place mocks into Spring Application Contexts. If Spring Application Context does already have a bean of the same type then this bean will be replaced with a mock object. Otherwise, a new bean(mock)…
Read More How to use @MockBean Annotation
In the world of testing, mock objects are used to simulate the behavior of real objects in the application. Mockito is a popular framework for creating mock objects in Java. A Spy in Mockito is a type of mock object that allows you to create a partial mock of an object by spying on an…
Read More Mockito Spy Explained: A Comprehensive Guide
Mockito enables partial mocking of an object, allowing us to create a mock object while still invoking a real method. To achieve this, we can use Mockito’s thenCallRealMethod() method to call a real method on a mocked object. I have also created several step-by-step video lessons that demonstrate how to test Java applications. If you…
Read More Mockito – Call a Real Method