Tag Archives: jmockit

Illegal Access Error with Mock Private Methods in JUnit

When I write some unit test with Junit and JMockit, I make a mock for some private methods as

MockUp<MyClass> myMethod = new MockUp<MyClass>() {
     @Mock
     private void mockMethod() {
     }
};

however when it runs I got this error.

java.lang.IllegalAccessError: tried to access method path-to-test-file(;path-to-file-which-tested)
	at ...

Click to read more…

Advertisements
Tagged ,

How to Mock a Hibernate Session with JMockit

I’m writing some unit tests with JUnit but my tests crash with NullPointerException in the line

Session session = sessionFactory.getCurrentSession();

There are also some session functions like flush and clear.

So I decided to write a mock object for that session, therefore tests can pass that line without got an exception.

Click to read more…

Tagged , ,