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…

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…

Junit Mockito Verify Example

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 actual method has been executed…

Junit Testing Of File Upload And Download

Junit Test Here in this tutorial you will see examples on Junit testing of file upload and download in Spring REST Controllers. You might have seen how to write Junit test cases on Spring REST Controllers in my other tutorials but I did not show how to write Junit testing of file upload and download in Spring REST Controllers but…

Writing Junit Test on Java Thread

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.

TDD – Test Driven Development

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 to step 1.

Junit Testing Spring REST Services

Introduction In this tutorial we will see how to write Junit test cases on Spring REST services. Before continue to reading this tutorial please read first Spring RESTful Webservice CRUD Example We have total four operations on this REST example. If you want you may add more operation such as find all products and apply Junit on it.

Junit Code Coverage using Gradle, Jacoco

For your Java application you need to check the code coverage of your Junit test classes. Code coverage ensures your code quality for the Junit test cases you have written for your functionalities of the application. Here I am going to show you how you can use Jacoco plugin to test the coverage. Currently it supports instruction, branch, line, method…

Junit 4 Test Suite Example in Java

In this example I am going to explain how to use a test suite in Junit testing framework in Java programming language. A test suite bundles a few unit test cases and runs them together. In Junit, both @RunWith and @Suite annotations are used to run the suite test. Junit Classes : Junit classes are important classes which used in…

Junit Code Coverage with Jacoco

Introduction In this post I will show you how to work with Junit code coverage with JaCoCo code coverage library, which is quite a new maven plug-in that provides the JaCoCo runtime agent to your tests and allows basic report creation. Currently it supports instruction, branch, line, method and class coverage which is pretty enough you can expect from this…