spring junit testing

前端 未结 3 1414
无人共我
无人共我 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 07:11

    You should use the SpringJUnit4ClassRunner on your test classes, and use @Resource (or @Autowired) on the field in your test class that contains the bean. You should consider having a special test context Spring configuration that uses stubs so that your tests are genuine unit tests, and don't rely on the whole application context.

提交回复
热议问题