我已经为返回String的私有函数编写了JUnit。 它工作正常。如何写一个返回布尔值的私有函数的JUNIT?
public void test2() throws Exception
{
MyHandler handler = new MyHandler();
Method privateStringMethod = MyHandler.class.getDeclaredMethod("getName", String.class);
privateStringMethod.setAccessible(true);
String s = (String) privateStringMethod.invoke(handler, 852l);
assertNotNull(s);
}
我有一个函数返回布尔值,但这是行不通的。 但是,我得到一个编译时错误说Cannot cast from Object to boolean.
public void test1() throws Exception
{
MyHandler handler = new MyHandler();
Method privateStringMethod = MyHandler.class.getDeclaredMethod("isvalid", Long.class);
privateStringMethod.setAccessible(true);
boolean s = (boolean) privateStringMethod.invoke(handler, 852l);
assertNotNull(s);
}
如何运行
不isValid()的返回** **布尔**或**布尔? – Jim 2012-03-27 10:51:35
@Jim它返回布尔值。 – vikiiii 2012-03-27 10:53:40