File tree Expand file tree Collapse file tree 3 files changed +126
-4
lines changed Expand file tree Collapse file tree 3 files changed +126
-4
lines changed Original file line number Diff line number Diff line change 1
1
public class Calculator {
2
- int add (int a , int b ) {
2
+ public int add (int a , int b ) {
3
3
return a + b ;
4
4
}
5
5
6
- int subtract (int a , int b ) {
6
+ public int subtract (int a , int b ) {
7
7
return a - b ;
8
8
}
9
9
10
- int multiply (int a , int b ) {
10
+ public int multiply (int a , int b ) {
11
11
return a * b ;
12
12
}
13
13
14
- int divide (int a , int b ) {
14
+ public int divide (int a , int b ) {
15
15
if (b == 0 ) {
16
16
throw new ArithmeticException ("0으로 나눌 수 없습니다." );
17
17
}
Original file line number Diff line number Diff line change
1
+ import org .junit .jupiter .api .DisplayName ;
2
+ import org .junit .jupiter .api .Test ;
3
+
4
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
5
+
6
+ @ DisplayName ("Calculator Assert Test" )
7
+ public class CalculatorAssertTest {
8
+
9
+ private Calculator calculator = new Calculator ();
10
+
11
+ @ Test
12
+ @ DisplayName ("add" )
13
+ void add_test () {
14
+ int a = 1 ;
15
+ int b = 2 ;
16
+ int expected = a + b ;
17
+
18
+ int actual = calculator .add (1 , 2 );
19
+
20
+ assertEquals (expected , actual );
21
+ }
22
+
23
+ @ Test
24
+ @ DisplayName ("subtract" )
25
+ void subtract_test () {
26
+ int a = 1 ;
27
+ int b = 2 ;
28
+ int expected = 1 - 2 ;
29
+
30
+ int actual = calculator .subtract (a , b );
31
+
32
+ assertEquals (expected , actual );
33
+ }
34
+
35
+ @ Test
36
+ @ DisplayName ("multiply" )
37
+ void multiply_test () {
38
+ int a = 1 ;
39
+ int b = 2 ;
40
+ int expected = a * b ;
41
+
42
+ int actual = calculator .multiply (a , b );
43
+
44
+ assertEquals (expected , actual );
45
+ }
46
+
47
+ @ Test
48
+ @ DisplayName ("divide" )
49
+ void divide_test () {
50
+ int a = 1 ;
51
+ int b = 2 ;
52
+ int expected = a / b ;
53
+
54
+ int actual = calculator .divide (a , b );
55
+
56
+ assertEquals (expected , actual );
57
+ }
58
+ }
Original file line number Diff line number Diff line change
1
+ import org .junit .jupiter .api .DisplayName ;
2
+ import org .junit .jupiter .api .Test ;
3
+
4
+ @ DisplayName ("Calculator junit5 Test" )
5
+ public class CalculatorJUnit5Test {
6
+
7
+ private Calculator calculator = new Calculator ();
8
+
9
+ @ Test
10
+ @ DisplayName ("add" )
11
+ void add_test () {
12
+ int a = 1 ;
13
+ int b = 2 ;
14
+ int expected = a + b ;
15
+
16
+ int actual = calculator .add (1 , 2 );
17
+
18
+ if (actual != expected ) {
19
+ throw new RuntimeException ("expected: <" + expected + "> but was: <" + actual + ">" );
20
+ }
21
+ }
22
+
23
+ @ Test
24
+ @ DisplayName ("subtract" )
25
+ void subtract_test () {
26
+ int a = 1 ;
27
+ int b = 2 ;
28
+ int expected = 1 - 2 ;
29
+
30
+ int actual = calculator .subtract (a , b );
31
+
32
+ if (actual != expected ) {
33
+ throw new RuntimeException ("expected: <" + expected + "> but was: <" + actual + ">" );
34
+ }
35
+ }
36
+
37
+ @ Test
38
+ @ DisplayName ("multiply" )
39
+ void multiply_test () {
40
+ int a = 1 ;
41
+ int b = 2 ;
42
+ int expected = a * b ;
43
+
44
+ int actual = calculator .multiply (a , b );
45
+
46
+ if (actual != expected ) {
47
+ throw new RuntimeException ("expected: <" + expected + "> but was: <" + actual + ">" );
48
+ }
49
+ }
50
+
51
+ @ Test
52
+ @ DisplayName ("divide" )
53
+ void divide_test () {
54
+ int a = 1 ;
55
+ int b = 2 ;
56
+ int expected = a / b ;
57
+
58
+ int actual = calculator .divide (a , b );
59
+
60
+ if (actual != expected ) {
61
+ throw new RuntimeException ("expected: <" + expected + "> but was: <" + actual + ">" );
62
+ }
63
+ }
64
+ }
You can’t perform that action at this time.
0 commit comments