spring junit testing

前端 未结 3 1415
无人共我
无人共我 2020-12-10 06:35

I have a maven spring project (latest version) and I want to write some junit tests (latest version).

The issue I have is that my spring beans are autowired, and whe

3条回答
  •  甜味超标
    2020-12-10 06:48

    This is a possibility:

    @RunWith(SpringJUnit4ClassRunner.class)
    // ApplicationContext will be loaded from "/applicationContext.xml"
    // in the root of the classpath
    @ContextConfiguration({"/applicationContext.xml"})
    public class MyTest {
    // class body...
    }
    

    Usually it's a good idea though to have a test-applicationContext for your test infrastructure.

提交回复
热议问题