JUnit5 & Mockito
Akshat0210
5,123 views
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
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// {
class AssertionsInJUnitFiveTest {
@Test
public void test() throws FileNotFoundException {
try {
success(true);
} catch (AssertionError ae) {
// {
success(false);
msg("Oops! 🐞", ae.getMessage());
//}
}
}
// {
private static void success(boolean success) {
if(success)
msg("👍" ," Awesome");
System.out.println(String.format("TECHIO> success %s", success));
}
private static void msg(String channel, String msg) {
System.out.println(String.format("TECHIO> message --channel \"%s\" \"%s\"", channel, msg));
}
//}
}
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 {
}
Mockito in JUnit 5
- Write Mockito Based test case for Messenger class
Mockito in JUnit5
1
11
12
13
14
15
// {
class MessengerTest {
}
1
package com.tu.code.junit5;
1
package com.tu.code.junit5;
1
package com.tu.code.junit5;
1
2
3
4
5
package com.tu.code.junit5;
public class Template {
}
1
package com.tu.code.junit5;
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD Online Participants