-1

I have a

@Component
public class MyBean{

         @Autowired
         Bean1 bean1;

         @Autowired
         Bean2 bean2;

         public void create(Param param1, Param param2){
           SomeObject object =    bean2.getDesiredResult();
         }

}

where Bean2.java has instance variables which are autowired-

class Bean2{
    @Autowired
    Bean3 bean3;

    @Autowired
    Bean4 bean4;

    @Autowired
    Bean5 bean5;

    public Object getDesiredResult(){
        // some code which calls method on some beans which have autowired
        // beans, and this goes on and on further.
    }

}

I have to test this method,

create(Param param1, Param param2)

The major problem is I continue to get these exceptons:

No qualifying bean of type
Could not autowire field

because I cannot manually component-scan all the packages as they are so large in number. There are around 3000 java packages in the project

<context:component-scan base-package

I am using JUnit & EasyMock frameworks. Please suggest.

Farhan stands with Palestine
  • 13,890
  • 13
  • 58
  • 105

1 Answers1

0

You seem to be mixing two things. You want to do a unit test with JUnit and EasyMock. This do not require Spring or any autowire. You will do the following:

// Record the mock
Bean2 mock = createMock(Bean2.class);
expect(mock.getDesiredResult()).andReturn(new SomeObject());
replay(mock);

// Configure the tested class
MyBean testSubject = new MyBean();
testSubject.setBean(mock);

// Test
testSubject.create(new Param1(), new Param2());

// Check the mock was called as expected
verify(mock);

For the package scanning. Which is unrelated with the testing from my point of view, the package scan can be recursive.

Henri
  • 5,551
  • 1
  • 22
  • 29