【发布时间】:2014-12-12 01:08:18
【问题描述】:
我有一个静态方法,它将从类中的测试方法中调用,如下所示
public class MyClass
{
private static boolean mockMethod( String input )
{
boolean value;
//do something to value
return value;
}
public static boolean methodToTest()
{
boolean getVal = mockMethod( "input" );
//do something to getVal
return getVal;
}
}
我想通过模拟 mockMethod 为方法 methodToTest 编写一个测试用例。 尝试如下,它没有给出任何输出
@Before
public void init()
{
Mockit.setUpMock( MyClass.class, MyClassMocked.class );
}
public static class MyClassMocked extends MockUp<MyClass>
{
@Mock
private static boolean mockMethod( String input )
{
return true;
}
}
@Test
public void testMethodToTest()
{
assertTrue( ( MyClass.methodToTest() );
}
【问题讨论】:
标签: java unit-testing testing jmockit