美文网首页
Spring整合Junit

Spring整合Junit

作者: N最珍贵 | 来源:发表于2021-04-02 09:05 被阅读0次

    导入坐标

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.2.8.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>5.2.8.RELEASE</version>
    </dependency>
    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>4.12</version>
       <scope>test</scope>
    </dependency>
    
    //替换原来的运行器,让测试运行于Spring测试环境
    @RunWith(SpringJUnit4ClassRunner.class)
    //加载spring核心配置文件
    //@ContextConfiguration("classpath:applicationContext.xml")
    //加载spring核心配置类
    @ContextConfiguration(classes = {Configuration.class})
    public class Test {
    
        //注入testService对象
        @Autowired
        private TestServiceImpl testService;
    
        @Test
        public void test1(){
            testService.test();
        }
    }
    

    相关文章

      网友评论

          本文标题:Spring整合Junit

          本文链接:https://www.haomeiwen.com/subject/hjbtkltx.html