1 pom配置
testng + jmockit,使用junit也可以
org.testng
testng
6.14.3
test
org.jmockit
jmockit
1.41
test
2 程序结构
三步走:
录制,mock方法并返回指定结果
回放,调用mock的方法
验证,检查mock方法使用情况
public class App {
public String say(String name) {
return "Hello " + name;
}
}
---------------------------------------------
public class AppTest {
@Mocked App app;
@Test
public void testSay() {
//录制
new Expectations() { {
app.say(anyString);
result = "Hello World";
}};
//回放
System.out.println(app.say("Jack"));
//验证
new Verifications() { {
app.say(anyString);</