如何从JMockit模拟静态方法
2022-09-01 18:36:25
我有一个静态方法,它将从类中的测试方法调用为波纹管
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;
}
}
我想通过模拟模拟方法为方法方法ToTest编写一个测试用例。尝试作为波纹管,它没有给出任何输出
@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() );
}