美文网首页
SpringBoot项目使用Junit单元测试案例

SpringBoot项目使用Junit单元测试案例

作者: 拄杖忙学轻声码 | 来源:发表于2021-09-15 17:54 被阅读0次

一、引入 Junit 依赖包:

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>

二、编写测试用例代码:

@RunWith(value = SpringRunner.class)
@SpringBootTest
public class UnitTest {
    @Autowired
    private VhclFeignClient vhclFeignClient;

    @Test
    public void testOne(){
        CommonResult<Vhcl> vchlInfoById = vhclFeignClient.getVchlInfoById(1);
        System.out.println("vchlInfoById = " + vchlInfoById);
    }
}

说明:
1、@RunWith(value = SpringRunner.class) 注解代表系统会把 javabean 加载到 spring 容器中,否则无法注入接口对象

相关文章

网友评论

      本文标题:SpringBoot项目使用Junit单元测试案例

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