In this post under JUnit 5, I will show with example, the purpose and how to use “assertInstanceOf” method. The assertInstanceOf method from JUnit 5 can be used to verify whether an object is actually an instance of the specified class or not. If an object is actually an instance of passed in Class, then…… Continue reading AssertInstanceOf Example
Category: JUnit 5
AssertTimeout Example
In this post under Junit, I will show with example how to use and what is the purpose of AssertTimeout assertion method. AssertTimeout is used to verify whether a certain operation completes within the specified timeout or not. For our example we will use the below class to be tested. Class to be tested package…… Continue reading AssertTimeout Example
AssertSame Example
In this post under JUnit, I will show with example the purpose of AssertSame assertion method. JUnit 5 has added new assertion method “assertSame” that checks for Object reference equality. How “assertSame” is different from “assertEquals” assertion method is that latter check for Object value equality whereas former checks for Object reference equality. Object value…… Continue reading AssertSame Example
AssertDoesNotThrow Example
In this post under JUnit, I will explain with example what is the purpose and how to use “AssertDoesNotThrow” assertion method. AssertDoesNotThrow takes an executable code and assert that the method doesn’t throw any exception during execution. Below is the javadoc of “assertDoesNotThrow” exception public static void assertDoesNotThrow​(Executable executable) Where “Executable” is a functional interface…… Continue reading AssertDoesNotThrow Example
Assumptions in JUnit5
In this post under Junit5, I will show with example, how to use Assumptions feature. Sometimes test case assertions depend on certain conditions. If a condition is met, then test case should be asserted otherwise we should skip the assertion. To test whether the condition is met or not, we take the help of “assumeTrue”…… Continue reading Assumptions in JUnit5
Disabling the tests
In this post under Junit 5, I will show how to disable a test method or all test methods of a class. Junit 5 added a new annotation named “Disabled” to disable a test method or all the test methods of a class. When applied at a particular method, that particular method is disabled. When…… Continue reading Disabling the tests
assertTrue and assertFalse with Supplier Interface
In this post under JUnit 5, I will introduce you to a new overloaded version of “assertTrue” and “assertFalse” methods. In the earlier versions, we used to stored the result of a comparison in local variable of type boolean and when calling assertTrue or assertFalse, we used to pass that local variable as an argument…… Continue reading assertTrue and assertFalse with Supplier Interface
BeforeEach and AfterEach annotations
In this post under JUnit, I will show with example the purpose of BeforeEach and AfterEach annotations. As you know when writing unit test cases, before calling the test method and asserting the output, we should first setup the data on which the test method has to be executed. We can place the code that’s…… Continue reading BeforeEach and AfterEach annotations
AssertThrows example
In this post under Junit 5, I will show with example what is the purpose of and how to use AssertThrows feature. AssertThrows method checks whether the called method throws the user specified exception or not. If the user specified exception is thrown, the test passes otherwise the test fails. For our example, we will…… Continue reading AssertThrows example
Assertions using Supplier interface
In this post under JUnit 5, I will show with example, the new version of assert method which takes a Supplier interface implementation as an argument. In previous versions of JUnit, we have seen variety of assert methods, which takes the below arguments.1) The expected value (optional)2) The actual value (required)3) String message when the…… Continue reading Assertions using Supplier interface