Junit 5 Test Report Using SonarQube Jacoco Gradle

Table of Contents Introduction Prerequisites Project Setup The Junit 5 Test Class Generating Test Reports Scanning Project with Sonar Source Code Introduction In this Spring Boot based application I am going to show you how to generate Junit 5 test report using SonarQube Jacoco gradle build tool. You need to generate such test reports to ensure that your source code…

Spring JdbcNamedParameterTemplate Junit Mockito

Introduction In the tutorial, Spring NamedParameterJdbcTemplate and MapSqlParameterSource Example, I had shown how to save new record in the database and how to fetch record from database. Here I am going to show you how to mock Spring JdbcNamedParameterTemplate SqlParameterSource with Junit Mockito. I am going to use Junit 5 framework for this example. I am also using Mockito framework…

Dynamic Tests – @TestFactory in Junit 5

Here in this tutorial I will tell you what are Dynamic Tests and @TestFactory in Junit 5 and how to create @TestFactory in Junit 5. Test cases, annotated with @Test, are static in the sense that they are fully specified at compile time, and their behavior cannot be changed by anything happening at runtime. In addition to these standard static…

How to test Private Methods using Junit 5

Introduction Here in this tutorial I will show you an example on how to test private methods using Junit framework. I am using Junit 5 framework to test the private method. Using Mockito framework you won’t be able to test private methods, but using PowerMock core API you will be able to test the private methods. You can also use…

Junit 5 Mockito Verify Example

In this example I am going to show you how to verify a method has been executed at least. Why do you need to verify method execution? Consider the void method, in your Java class, which you want to perform Junit test case on it and you don’t have any way to tell whether your method successfully tested or not….

Junit 5 Expected Exception using Assertions.assertThrows()

This example will show you how to work with expected exception using Junit 5 Assertions.assetThrows(). Junit 4 (at least 4.7 version) provides expected attribute with @Test annotation, where you can mention what exception you are expecting from your test method but Junit 5 does not provide such thing. Junit 5 provides assertThrows() that can be used to check the expected…

Mock an Autowired Value Field in Spring with Junit 5

Mock @Value In this example I am going to show you how to mock an autowired field in Spring boot framework with Junit 5. When you use @Value annotation in Spring beans to read the value from properties file and later when you want to perform Junit test then you also need to pass value for this autowired field value…

Junit Testing for Multiple Files Upload Spring REST Controller

Introduction Here I am going to write Junit test case for testing multiple files upload in Spring REST Controller. I have already created how to upload multiple files using Spring REST API and I also had shown how to test it through REST client tool – Postman. In this tutorial I am going to use Junit 5, @WebMvcTest annotation to…

Java Junit 5 Mockito doNothing() Example

In this tutorial I am going to show you how to work with Mockito‘s doNothing() in Java Junit 5 API. Mockito‘s doNothing() or Mockito itself is widely used testing framework. If you are working with Junit 4 then you can read the similar example Mockito’s doNothing() using Junit 4. Mockito‘s doNothing() is used when you want to test void methods…

Cucumber Tags Example

Introduction In this tutorial you will see how to work on Cucumber Tags. Tags in Cucumber are great ways to organize your features and scenarios. It is pretty much simple when you have one, two, or maybe five scenarios in a feature file. However, in real life project, for each feature, you may have 20, 30, or may be more…