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…

Posted in Junit Spring Boot Spring JDBC

Spring JdbcNamedParameterTemplate Junit Mockito

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…

Posted in Junit

Dynamic Tests – @TestFactory in 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…

Posted in Junit Spring Boot

How to test Private Methods using Junit 5

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…

Posted in Junit

Junit 5 Mockito Verify Example

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…

Posted in Junit

Junit 5 Expected Exception using Assertions.assertThrows()

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…

Posted in Junit Spring Boot

Mock an Autowired Value Field in Spring with Junit 5

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…

Posted in Junit Spring REST

Junit Testing for Multiple Files Upload Spring REST Controller

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…

Posted in Junit

Java Junit 5 Mockito doNothing() Example

Introduction In this tutorial we will see how to check broken links in website using Selenium web driver. Broken links are not reachable or simply do not work. A URL for the website is no longer available. A URL of the web page was moved without a redirect being added. The URL structure of a…

Posted in Java Selenium Web

How to check broken links in Website using Selenium Web Driver

Introduction This tutorial will show you how to perform automation testing using Cucumber and Selenium web driver. Cucumber is a BDD framework used to perform behavior testing whereas Selenium is used to perform automation testing for web applications across different browsers and platforms. In this example we will search a keyword in Google website and…

Posted in Cucumber Java Selenium Web

Automation Testing using Cucumber and Selenium Web Driver

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,…

Posted in Cucumber Junit

Cucumber Tags Example

Introduction We will see the use of @WebMvcTest annotation in Spring MVC applications. The Spring MVC application may be Spring Boot application as well. The @WebMvcTest annotation can be used not only to test Spring Controllers but also Spring REST Controllers. We will build the applications using both maven and gradle tools. @WebMvcTest annotation is…

Posted in Junit Spring Boot Spring MVC Spring REST

@WebMvcTest Annotation Example in Spring MVC Applications