0
package pack1;

class ClassToBeTest{

    private void method1(){ 
        boolean check = method2();
    }
    private boolean method2(){ 
        return false;
    }
}

package pack2;

public class TestClass{

    @Test
    public void test_method1() {
        Object obj = Deencapsulation.newInstance("pack1.ClassToBeTest");
        Deencapsulation.invoke(obj, "method1");
    }
}

We see above that the ClassToBeTested is not public and hence not accessible outside its package, whereas all our test classes are in different packages. We can invoke the method of the class using JMockit's Deencapsulation APIs but how do we mock the method2() ?

Keppil
  • 45,603
  • 8
  • 97
  • 119
  • Why isn't your test class in the same package as the real class? – Keppil Jul 10 '15 at 11:10
  • Thanks for editing and making the code readable. We are testing JMockit's capabilities of testing unaccessible code. Did not find in JMockit documentation for any such limitations. – Rajesh Choudhari Jul 13 '15 at 06:33
  • One more reason for keeping them separate is we would like to keep the Code Coverage of the "Classes to be Tested", separate from our Test-Classes (TestNG/JMockit ). In Eclipse, if we keep both the classes in the same package, then the Package Level Code Coverage of the "Classes to be Tested" is inaccurate. – Rajesh Choudhari Jul 13 '15 at 08:58

0 Answers0