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
The java.lang.OutOfMemoryError is a runtime exception in Java that occurs when the Java Virtual Machine (JVM) exhausts all available memory and is unable to allocate more memory to fulfill the memory requirements of an application. This error indicates that the application has run out of heap space and is unable to create new objects or…
Read More java.lang.OutOfMemoryError: Resolving Memory Management Issues
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 are preparing for a Spring Boot interview or simply looking to enhance your knowledge of this powerful Java framework, you’ve come to the right place. In this page, we will delve into a collection of commonly asked interview questions related to Spring Boot. From fundamental concepts to advanced topics, we will cover essential…
Read More Essential Spring Boot Interview Questions
Welcome, and thank you for choosing this tutorial! 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…
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
This tutorial will teach you how to use the @Query annotation to execute custom SQL queries. Spring Data JPA provides many query methods that are ready to use, allowing us to perform basic CRUD(Create, Read, Update and Delete) operations. However, there may be situations where we need to execute a custom SQL query even though…
Read More Spring Data JPA Native SQL Query
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