Java 如何在Junit测试中使用JMockit测试私有方法

Java 如何在Junit测试中使用JMockit测试私有方法,java,junit,jmockit,Java,Junit,Jmockit,我想测试私有方法的函数。 我还想检查参数何时为“null” 是否可以使用JMockit测试私有方法? 我该怎么办 目的:我想测试所有案例,以满足覆盖率测试的要求 实际代码 @Test public void testLogic() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {

我想测试私有方法的函数。 我还想检查参数何时为“null”

是否可以使用JMockit测试私有方法? 我该怎么办

目的:我想测试所有案例,以满足覆盖率测试的要求

实际代码

    @Test
    public void testLogic() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
        Service serviceTest = new ServiceTest();

        int expected = false;
        Method method = Service.class.getDeclaredMethod("testMethod", String.class, String.class)  ;
        method.setAccessible(true);
        boolean actual = (boolean)method.invoke(serviceTest, "aaa",new Object[]{null});
        assertEquals(false, actual);

    }


测试代码

    private boolean testMethod(String test,String testNull) throws IOException
    {
        if(testNull== null)
        {

            return false;
        }

            return true;

    }