File tree Expand file tree Collapse file tree
junit5/src/test/java/com/baeldung Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import org .junit .gen5 .api .Test ;
44
5+ import static org .junit .gen5 .api .Assertions .assertEquals ;
56import static org .junit .gen5 .api .Assumptions .assumeFalse ;
67import static org .junit .gen5 .api .Assumptions .assumeTrue ;
78import static org .junit .gen5 .api .Assumptions .assumingThat ;
@@ -11,21 +12,21 @@ public class AssumptionTest {
1112 @ Test
1213 void trueAssumption () {
1314 assumeTrue (5 > 1 );
14- System . out . println ( "Was true" );
15+ assertEquals ( 5 + 2 , 7 );
1516 }
1617
1718 @ Test
1819 void falseAssumption () {
1920 assumeFalse (5 < 1 );
20- System . out . println ( "Was false" );
21+ assertEquals ( 5 + 2 , 7 );
2122 }
2223
2324 @ Test
2425 void assumptionThat () {
2526 String someString = "Just a string" ;
2627 assumingThat (
2728 someString .equals ("Just a string" ),
28- () -> System . out . println ( "Assumption was correct" )
29+ () -> assertEquals ( 2 + 2 , 4 )
2930 );
3031 }
3132}
Original file line number Diff line number Diff line change 22
33import org .junit .gen5 .api .Test ;
44
5+ import java .util .ArrayList ;
6+
57import static org .junit .gen5 .api .Assertions .assertEquals ;
68import static org .junit .gen5 .api .Assertions .expectThrows ;
79
810public class ExceptionTest {
911
1012 @ Test
1113 void shouldThrowException () {
12- Throwable exception = expectThrows (NullPointerException .class , null );
14+ ArrayList list = null ;
15+ Throwable exception = expectThrows (NullPointerException .class , list ::clear );
1316 assertEquals (exception .getClass (), NullPointerException .class );
1417 }
1518}
Original file line number Diff line number Diff line change 11package com .baeldung ;
22
3+ import org .junit .gen5 .api .Disabled ;
34import org .junit .gen5 .api .Test ;
45
56import static org .junit .gen5 .api .Assertions .assertAll ;
@@ -11,7 +12,7 @@ class FirstTest {
1112 @ Test
1213 void lambdaExpressions () {
1314 String string = "" ;
14- assertTrue (() -> string . isEmpty () , "String should be empty" );
15+ assertTrue (string :: isEmpty , "String should be empty" );
1516 }
1617
1718 @ Test
@@ -24,4 +25,9 @@ void groupAssertions() {
2425 });
2526 }
2627
28+ @ Test
29+ @ Disabled
30+ void disabledTest () {
31+ assertTrue (false );
32+ }
2733}
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import org .junit .gen5 .api .Tag ;
4+ import org .junit .gen5 .api .Test ;
5+
6+ import static org .junit .gen5 .api .Assertions .assertEquals ;
7+
8+ @ Tag ("Test case" )
9+ public class TaggedTest {
10+
11+ @ Test
12+ @ Tag ("Method" )
13+ void testMethod () {
14+ assertEquals (2 +2 , 4 );
15+ }
16+ }
You can’t perform that action at this time.
0 commit comments