【发布时间】:2017-11-14 08:31:03
【问题描述】:
我有一个类 A,它有一个私有整数成员 b。这是类的结构:
public class A {
private int b= Integer.parseInt(C.getValue(anyString));
public int getB() {
return b;
}
public void setB(int b) {
this.b= b;
}
}
我正在使用 jmockit 和 junit4 测试这个类的一些方法`
public class ATest {
@Tested
A a;
@BeforeClass
public void setUp() {
//mock C.getValue
}
@Test public void test1() {
//some test code
}
}
但我无法模拟调用 (C.getValue(anyString)),因此在构建项目时测试失败。我尝试过使用@Before 和@BeforeClass,但没有一个执行过一次。请提出出路。
考虑到我不能更改主类A。
【问题讨论】:
-
C是什么类型的类?
-
假设它是一个为特定键执行数据库查找的类。
-
尝试使用 NonStrictExpectation 进行部分模拟
标签: java unit-testing junit jmockit