美文网首页
SpringBoot使用JUnit进行测试

SpringBoot使用JUnit进行测试

作者: 天马行空_9f6e | 来源:发表于2022-07-27 11:49 被阅读0次

新建SpringBoot项目后基本会包含下面引用,所以基本不用引入其他maven引用

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-test</artifactId>

    <scope>test</scope>

    <exclusions>

        <exclusion>

            <groupId>org.junit.vintage</groupId>

            <artifactId>junit-vintage-engine</artifactId>

        </exclusion>

    </exclusions>

</dependency>


新建测试类,添加SpringBootTest注解,后面的classes参数为SpringBoot启动类,在测试方法上加上@Test注解即可

@SpringBootTest(classes = TestredisApplication.class)

public class ProductServiceImplTest {

    @Test

    public void addInfoToRedis() {

        productService.addInfoToRedis();

    }

}

相关文章

网友评论

      本文标题:SpringBoot使用JUnit进行测试

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