spring junit testing

前端 未结 3 1404
无人共我
无人共我 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:50

    Have you studied Testing chapter in Spring reference documentation? Here is an example you should start with:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration
    public class MyTest {
    
        @Resource
        private FooService fooService;
    
        // class body...
    }
    

    If you are in com.example.MyTest in /src/test/java, you will need /src/test/resources/com/example/MyTest-context.xml - but the exceptions will show you the way.

提交回复
热议问题