In this tutorial, you will learn about @SpringBootTest annotation. You will use this annotation to write Integration Tests for your Spring Boot application. @SpringBootTest annotation is used to create a Spring Application Context that will be used during the test. It will make Spring Framework scan your application classes and look for different annotations. Depending…Read More @SpringBootTest Annotation Example
This article will explore the JUnit 5 Assertions API, go in-depth with examples of building fundamental assertions, and look at customizing the error message that appears when an assertion fails. We’ll also discuss how to execute many assertions simultaneously as an assertion group in our last section. So, let’s begin! What are JUnit Assertions? As…Read More An Overview of JUnit 5 Assertions with Examples
In this blog post, you will learn the difference between @SpringBootTest and @WebMvcTest annotations. The main difference between the @SpringBootTest and @WebMvcTest annotations lies in the application context that they create. The @SpringBootTest annotation starts the full application context, which includes all the beans required for the application to function. On the other hand, the…Read More Difference Between @SpringBootTest and @WebMvcTest
In this blog post, you will learn a couple of ways you can disable Spring Security Configuration for your @WebMvcTest. Disable Security Filters for @AutoConfigureMockMvc One of the ways you can disable Spring Security filters in your tests, is to use the @AutoConfigureMockMvc annotation. @AutoConfigureMockMvc annotation can be applied to a test class to enable…Read More Disable Spring Security Configuration for @WebMvcTest
This tutorial will teach you how to enable Mockito framework in your Spring Boot project and in addition to that, you will also learn how to use @Mock and @InjectMocks annotations to create mock objects and inject those mock objects into the class under test. If you are very new to Mockito, please consider reading…Read More Getting Started with Mockito @Mock and @InjectMocks
In this tutorial, I am going to share with you how to make your JUnit tests run in order. And if you are interested to learn more about testing your RESTful Web Services with JUnit and Rest Assured check this list of tutorials: Building and Testing RESTful Web Services. By default, test classes and methods will…Read More How to Run JUnit Tests in Order
In this tutorial, you will learn about a way or a pattern to structure your code inside of a unit test method. If you follow this pattern consistently, then it will be easier to read and understand code inside of your test methods. This pattern is widely used by many developers and is know as Arrange, Act, Assert(AAA).…Read More How to Structure Unit Test Method?
In this lesson, you will learn about the @Disabled annotation that will help you to disable the test. Usually, it is not a good idea to disable a test. If the test is failing for some reason and you are not sure why it is failing, do not disable it. Try to figure out why…Read More How to Disable JUnit Test Method with @Disabled Annotation
This tutorial will teach you how to build a Maven-based Spring Boot project and skip Unit tests. Sometimes, when working on a project, we need to build and run it even though our Unit test is failing. When there is a flailing Unit test, the Maven package and install commands will also fail. This is because…Read More How to Skip Unit Tests in Maven
In this JUnit 5 and Rest Assured tutorial, I am going to share with you how to add JUnit 5 and Rest Assured support to your Spring Boot project. It will be more than that actually. This tutorial will cover: Add JUnit 5 and Rest Assured to Spring Boot Project, Create a new JUnit 5…Read More Create a JUnit 5 Test Case with Rest Assured. Video Tutorial.
In this short tutorial on REST Assured you will learn how to get the entire HTTP Response Body when testing your RESTful Web Service Endpoint. Web Service Endpoint Response Let’s assume we have the following Web Service Endpoint URL and when HTTP GET request is made to this Web Service Endpoint a JSON representation of…Read More REST Assured Get HTTP Response Body
In this REST Assured tutorial, you will learn how easy it is to test and validate RESTful APIs. REST Assured provides excellent HTTP support, explicit verbs, and actions. We will use REST Assured in this tutorial and the Hamcrest library to perform assertions. REST Assured Maven Dependencies Before laying down examples for this library, we need…Read More REST Assured Tutorial
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