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

Introduction In this example we will create Junit 5 parameterized tests. In our previous example we have seen how to configure Junit 5 for Java projects. In parameterized tests it is possible to run a test multiple times with different arguments. The @ParameterizedTest annotation is used in the regular @Test methods to indicate parameterized tests….

Posted in Java Junit

Junit 5 Parameterized Tests Examples

Introduction Here in this tutorial I will tell you how to exclude Junit test cases from build automation in Java applications. It’s not about skipping test cases but it’s about excluding test cases for a particular package. Situations may arise when you want to exclude some Junit test cases from running in some environments (for…

Posted in Gradle Junit Maven

How To Exclude Junit Tests Using Gradle Or Maven In Java Applications

Introduction Here I will show you how to configure Junit 5 using maven and Gradle in Eclipse. To get started with Junit 5, you need at least a single TestEngine implementation, for example, junit-jupiter-engine. We will show here both maven and gradle version dependencies for Junit 5. This TestEngine will pull in all the required…

Posted in Junit

How to configure Junit 5 using Maven and Gradle in Eclipse

Introduction In this tutorial we will see how to mock Activiti TaskService, TaskQuery, NativeTaskQuery in Junit class. Suppose you have Spring service class where you are doing some business flow for your application. So you are using Activiti‘s TaskService to create a list of activiti Tasks using the method createNativeTaskQuery(). You may need to create…

Posted in Activiti Junit

Mock Activiti TaskService, TaskQuery, NativeTaskQuery in Junit

This tutorial example will show you how to mock ObjectFactory<KieSession>, KieSession and KieStatelessSession using Junit. KieSession is the most common way to interact with the engine in Drools. A KieSession allows the application to establish an iterative conversation with the engine, where the state of the session is kept across invocations. The reasoning process may…

Posted in Drools Junit

Mock Drools ObjectFactory, KieSession and StatelessKieSession using Junit

Introduction This example will show you how to mock ObjectMapper.readValue() using Junit Mockito. When we write Junit test cases or classes, we generally do not test on real object that are injected into the class that has to be tested using Junit to avoid any test case failure at some point, instead we want to…

Posted in Junit

Mock ObjectMapper.readValue() using Junit Mockito

Introduction The below example will show you how to mock an Autowired @Value field in Spring with Junit Mockito. Generally you read some configuration values from properties file into Spring bean or component class using @Value annotated attributes but when you want to test such service or component class using Junit test class then it…

Posted in Junit

Mock an Autowired @Value field in Spring with Junit Mockito

Introduction The tutorial Junit Mockito Verify method will show you how to verify a Java class method has been executed at least once or not. When you write Junit test case for void method then you cannot return anything from your actual method test but at the same time you also don’t know whether your…

Posted in Junit

Junit Mockito Verify Example

Introduction Here in this tutorial we will see examples on Junit testing of file upload and download in Spring REST Controllers. We have seen how to write Junit test cases on Spring REST Controllers in my previous tutorial but I did not show how to write Junit testing of file upload and download in Spring…

Posted in File Download File Upload Junit Spring REST

Junit Testing of File Upload and Download in Spring REST Controllers

Introduction In this tutorial you will see how to write test case on Java thread using junit. Writing junit test on Java thread will show an example on single threaded environment.

Posted in Java Junit

Writing Junit Test on Java Thread

TDD or Test Driven Development is related to the test-first programming concepts of extreme programming. Test driven development where you write test before you develop a final code for your application. Life cycle of test-driven development: Write a test Run the written test Write code that corrects the failing test Clean up your code Go…

Posted in Java Junit

TDD – Test Driven Development