Posted in Junit

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…

Continue Reading... Java Junit 5 Mockito doNothing() Example
Posted in Cucumber Junit

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…

Continue Reading... Cucumber Tags Example
Posted in Junit Spring Boot Spring MVC Spring REST

@WebMvcTest Annotation Example in Spring MVC Applications

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 used for unit testing of…

Continue Reading... @WebMvcTest Annotation Example in Spring MVC Applications
Posted in Java Junit

Junit 5 Parameterized Tests Examples

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. In addition, at least one…

Continue Reading... Junit 5 Parameterized Tests Examples
Posted in Gradle Junit Maven

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

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 example, uat, prod, etc.) while…

Continue Reading... How To Exclude Junit Tests Using Gradle Or Maven In Java Applications
Posted in Junit

How to configure Junit 5 using Maven and Gradle in Eclipse

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 dependencies. Among those dependencies is…

Continue Reading... How to configure Junit 5 using Maven and Gradle in Eclipse
Posted in Activiti Junit

Mock Activiti TaskService, TaskQuery, NativeTaskQuery in Junit

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 also TaskQuery from TaskService using…

Continue Reading... Mock Activiti TaskService, TaskQuery, NativeTaskQuery in Junit
Posted in Drools Junit

Mock Drools ObjectFactory, KieSession and StatelessKieSession using 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 be triggered multiple times for…

Continue Reading... Mock Drools ObjectFactory, KieSession and StatelessKieSession using Junit
Posted in Junit

Mock ObjectMapper.readValue() using Junit Mockito

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 test the business logic out…

Continue Reading... Mock ObjectMapper.readValue() using Junit Mockito
Posted in Junit

Mock an Autowired @Value field in Spring with Junit Mockito

Mock @Value Field 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 is required to…

Continue Reading... Mock an Autowired @Value field in Spring with Junit Mockito