Question

I am trying to mock java.awt.Toolkit.beep() using JMockit Expectations. I have the following code in my test case:

new Expectations() {
    Toolkit mock;

    {
        mock.beep();
    }
}.endRecording();

When I run the test case (JUnit 4), I get the following exception at the "new Expectations" line:

java.lang.ClassFormatError: Code attribute in native or abstract methods in class file $Mock

Any ideas?

Was it helpful?

Solution

The default jmock can only mock interface. To mock class, you need to following these instructions

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top