我有以下课程
public class TestClass{
ParamObject paramObject = null;
public TestClass(ParamObject paramObject){
this.paramObject = paramObject;
}
public String getQuery(String field){
String sql = field + "sometext" + getName();
}
private String getName(){
SomeObject obj = new SomeObject();
return obj.getName();
}
}
我想模拟类的上述 getName 方法。构造函数参数在 Test 类中可用。我该怎么做呢。
@Test(groups = { "UNIT", "CS_RAJAN" })
public void TestClass_Unit_Test() throws Exception {
ParamObject paramObject = get();//some param object
//some way to pass the paramObject to the class and mock the getName() method so that it returns "ABC"
}