In this post under JUnit, I will show with example the purpose and how to use JUnit 5’s “RepeatedTest” annotation. The “RepeatedTest” annotation is applied on a method. Once applied it indicates the JUnit that it has repeat testing of annotated method a specified number of times. Below is the snapshot showing how to use…… Continue reading @RepeatedTest annotation
Category: JUnit 5
assertIterableEquals example
In this post under JUnit, I will show with example how to assert whether a expected collection has same elements, at the same position when compared to actual collection. Pre JUnit 5, to do this,1) we have to iterate item by item in both collection (expected and actual) at the same time2) compare the items…… Continue reading assertIterableEquals example
assertThrows vs assertThrowsExactly example
In this post under JUnit, I will show with example the purpose of “assertThrowsExactly” method and how it is different with “assertThrows” method. I have explained with example, the purpose of “assertThrows” static method in previous posts. For recap, “assertThrows” method asserts that the test method throws the expected exception. If the test method doesn’t…… Continue reading assertThrows vs assertThrowsExactly example
beforeAll and afterAll annotation
In this post under JUnit, I will explain with example the purpose of “beforeAll” and “afterAll” annotations. In the previous post under JUnit, I covered about “beforeEach” and “afterEach” annotation. Similarly to “beforeEach” and “afterEach”, “beforeAll” and “afterAll” is applied to methods. But methods annotated with “beforeEach” and “afterEach” annotations are executed before and after…… Continue reading beforeAll and afterAll annotation
assertArraysEquals example
In this post under Junit 5, I will explain with example the purpose of “assertArraysEquals” method. We can use the “assertArraysEquals” method to assert whether two arrays are equal or not. Below is the complete main code for your reference. Main Class package package15;import static org.junit.jupiter.api.Assertions.assertAll;import static org.junit.jupiter.api.Assertions.assertArrayEquals;import org.junit.jupiter.api.Test;public class Example15 { @Test public void…… Continue reading assertArraysEquals example
assumingThat example
In this post under JUnit, I will explain the purpose of “assumingThat” assertion method. In my previous postAssumptions in JUnit 5 I showed you how to use “assumeTrue” and “assumeFalse” assumption statements. Lets add that code here again for recap Below is the class to be tested. MockUserRepository package package14;public class MockUserRepository { private boolean…… Continue reading assumingThat example
@TestInstance example
In this post under JUnit, I will explain with example the purpose of “TestInstance” annotation. By default when we execute a test class, for each test method, a separate instance of test class is created. Lets see an example. For our example I will create the below “Calculator” class that has to be tested. Calculator…… Continue reading @TestInstance example
AssertAll Example
In this post under JUnit 5, I will show with example the purpose of “assertAll” method. Pre JUnit 5, If a testcase had multiple assert statements, the testing of that testcase would stop immediately at the first assert statement that fails. So for example if we have below test method public void testMethod() { assert1…… Continue reading AssertAll Example
AssertInstanceOf Example
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
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