Injecting @Autowired private field during testing

The Solution to Injecting @Autowired private field during testing is

You can absolutely inject mocks on MyLauncher in your test. I am sure if you show what mocking framework you are using someone would be quick to provide an answer. With mockito I would look into using @RunWith(MockitoJUnitRunner.class) and using annotations for myLauncher. It would look something like what is below.

public class MyLauncherTest
    private MyLauncher myLauncher = new MyLauncher();

    private MyService myService;

    public void someTest() {


~ Answered on 2013-05-07 18:55:43

Most Viewed Questions: