4 comments

  1. You can still mock static class initializers and default constructors using jmockit. See the javadoc here…

    https://jmockit.dev.java.net/javadoc/mockit/Mock.html

    This was introduced in build 0.90.

    Using your example above the test case would look like this…

    @MockClass(realClass = ClassToMock.class)
    public static class Replacement {

    @Mock
    public void $clint() {
    // mock static initializer.
    System.out.println(“here i am”);
    }

    @Mock
    public void $init() {
    // mock default constructor.
    System.out.println(“i’m in here now!”);
    }

    }

    }

    Then in your setUp() method just do Mockit.setUpMocks(Replacement.class);

    Tim

  2. Thanks for the addition. I recently had a look at the latest version and there are some really useful additions (this being one of them).

    Paulb

  3. very thx

    Oyun

  4. I tried using $clinit(), just like Tim mentioned. But the System.out.println(“here i am”); is not getting printed.
    Any idea why it is not getting printed? Other methods in that mock class is getting called.

    Hema

Comments are closed.