Mockito Stub Exception – JUnit, TestNG

Sometimes our methods throw exceptions and we want to mock the object and test the exceptions. We can use Mockito mock objects with when() and thenThrow() to mock this scenario. Mockito Stub Exception – JUnit….

JUnit Assert Exception – JUnit 5 and JUnit 4

We can test expected exceptions using JUnit 5 assertThrows assertion. This JUnit assertion method returns the thrown exception, so we can use it to assert exception message too. JUnit Assert Exception Here is a simple….

JUnit vs TestNG

JUnit and TestNG are the most popular testing frameworks for Java applications. Both of these frameworks are really good and easy to use. So when it comes to chose the testing framework for your application,….

JUnit Annotations

JUnit testing framework is built on annotations. JUnit 5 is a major upgrade from JUnit 4. There are different modules and we need JUnit Platform and JUnit Jupiter API to create and run the test….

JUnit 5 Nested Tests

JUnit Jupiter @Nested annotation can be used to mark a nested class to be included in the test cases. When JUnit tests are executed, Nested classes are not scanned for test methods. We can explicitly….

JUnit 5 Dynamic Tests – @TestFactory, DynamicTest

JUnit @TestFactory annotation coupled with DynamicTest can be used to create a test factory method. JUnit Dynamic Tests JUnit @TestFactory methods must not be private or static. These methods must return a Stream, Collection, Iterable,….

JUnit Setup Maven – JUnit 4 and JUnit 5

JUnit 4 and JUnit 5 are completely different frameworks. They both serve the same purpose, but the JUnit 5 is a completely different testing framework written from scratch. It’s not using anything from JUnit 4….

JUnit HTML Report

When we configure maven-surefire-plugin to run our JUnit tests, it generates surefire-reports directory. This directory contains a txt file and an XML file for every test class. However, reading these files is not easy and….

JUnit Disable Enable Tests

JUnit 5 Jupiter API provides various ways to disable or enable a test. There are various annotations to help us easily disable/enable tests based on OS, JRE, System properties etc. We can also execute a….

JUnit Assumptions

JUnit Assumptions helps us in skipping a test for some specific scenario. Sometimes our test cases are dependent on the inputs, operating systems or any third party data. If our test is not written for….

Generic selectors
Exact matches only
Search in title
Search in content