Issue #27 on hold

Method stubbing before spring context initialization

Andrea Polci
created an issue

I have a test case where I need to stub some methods before the spring initialization is completed, as soon as the mock is created (for example because the mock is injected into other beans that calls some method during the initialization).

Unfortunately the methods annotated with Before are executed only when the spring initialization is complete.

A possible solution is a new annotation to mark a method that need to be called as soon as a mock is created.


public class TestCase {
    @Autowired @Qualifier("myMock")
    MyInterface mock1;

    public static void stubMyMock(MyInterface mock) {

In this case the method "stubMyMock" need to be executed as soon as the mock is created.

Comments (5)

  1. kubek2k repo owner

    maybe a better mechanism would be sth like

    @Autowired @Qualifier
    MyInterface mock1;
    class MyMockInitializer implements MockInitializer<MyInterface> {
          public void initMock(MyInterface mock) {
              ... init code ...
  2. Log in to comment