Injecting @Autowired private field during testing

后端 未结 6 1062
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 17:08

I have a component setup that is essentially a launcher for an application. It is configured like so:

@Component
public class MyLauncher {
    @Autowired
            


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 17:20

    Look at this link

    Then write your test case as

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration({"/applicationContext.xml"})
    public class MyLauncherTest{
    
    @Resource
    private MyLauncher myLauncher ;
    
       @Test
       public void someTest() {
           //test code
       }
    }
    

提交回复
热议问题