Spring中使用单元测试--探索

来源:互联网 发布:python黑帽子原码 编辑:程序博客网 时间:2024/06/05 01:08

在之前项目开发中比较少使用单元测试,偶然见到大神写的单元测试,来学习学习。

依赖:

  <!--junit4.11 单元测试依赖-->        <dependency>            <groupId>junit</groupId>            <artifactId>junit</artifactId>            <version>4.11</version>        </dependency>



单元测试方法

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations = "classpath:application-context.xml")public class getAddress {    @Resource    private CountryService countryService;    @Test    public void testGetAddress() throws Exception {        System.out.println(countryService.getAddress());    }}

右键运行:



结果: