forked from CPU-Code/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculatorTest.java
More file actions
72 lines (57 loc) · 1.35 KB
/
Copy pathCalculatorTest.java
File metadata and controls
72 lines (57 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package src.test;
import src.junit.Calculator;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class CalculatorTest {
/**
* 初始化方法:
* 用于资源申请,所有测试方法在执行之前都会先执行该方法
*/
@Before
public void init(){
System.out.println("init ......");
}
/**
* 释放资源方法:
* 在所有测试方法执行完后,都会自动执行该方法
*/
@After
public void close(){
System.out.println("close....");
}
/**
* 测试add方法
*/
@Test
public void testAdd(){
System.out.println("testAdd...");
//1.创建计算器对象
Calculator c = new Calculator();
//2.调用add方法
int result = c.add(1, 3);
System.out.println(result);
//3.断言 我断言这个结果是3
Assert.assertEquals(4, result);
}
/*
init ......
testAdd...
4
close....
* */
@Test
public void testSub(){
System.out.println("testSub.....");
//1.创建计算器对象
Calculator c = new Calculator();
int result = c.sub(3, 1);
Assert.assertEquals(2, result);
}
/*
init ......
testSub.....
close....
*/
}