我拆过的坑cycx

查询一下!

@RunWith(SpringRunner.class)什么时候必须写呢?

@RunWith(SpringRunner.class)这个注解作用是在test的时候建立spring上下文环境


当pom.xml中有


<dependencies>

    <dependency>

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

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

        <scope>test</scope>

    </dependency>

</dependencies>

这个依赖的时候,需要spring上下文环境就需要写这个注解


当pom.xml是下面这样时


 <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>

就不需要@RunWith(SpringRunner.class)这个注解了,因为已经有了spring上下文环境

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-BlogPHP 1.7.3

Copyright Your WebSite.Some Rights Reserved.