JUnit5 & Mockito
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Welcome!
This playground lets you get started quickly with a simple working example using Maven and JUnit5.
Hands-on Exercise
- Write an assertion to compare two String are equal.
- Write an assertion to check null.
- Write an assertion to check equality of two byte array.
Assertions in JUnit5
1
11
12
13
14
15
16
17
18
22
23
24
34
35
36
// {
class AssertionsInJUnitFiveTest {
@Test
public void test() throws FileNotFoundException {
try {
success(true);
} catch (AssertionError ae) {
// {
}
}
// {
}
Enter to Rename, Shift+Enter to Preview
HamCrest API Matchers
- Write a HamCrest Matcher to check Map has key “John”
- Write a HamCrest Matcher to check Map has entry “John , J”
Using HamCrest in JUnit5
1
12
13
14
15
16
17
// {
class HamcrestMatchersTest {
}
Enter to Rename, Shift+Enter to Preview
Mockito in JUnit 5
- Write Mockito Based test case for Messenger class
Mockito in JUnit5
1
11
12
13
14
15
// {
class MessengerTest {
}
Enter to Rename, Shift+Enter to Preview
1
package com.tu.code.junit5;
Enter to Rename, Shift+Enter to Preview
1
package com.tu.code.junit5;
Enter to Rename, Shift+Enter to Preview
1
package com.tu.code.junit5;
Enter to Rename, Shift+Enter to Preview
1
package com.tu.code.junit5;
Enter to Rename, Shift+Enter to Preview
1
package com.tu.code.junit5;
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content