SpringBoot单元测试时的小问题

跟着网上的视屏学习,通过IDEA生成的SpringBoot,删除无用的文件目录后,在首次接触yaml之后,将配置文件中配置的每一个属性的值,映射到这个组建中并测试时,老师的SpringBoot单元测试下面有@RunW ith注解,而我的没有,看弹幕后得知,有很多人有@RunWith(SpringRunner.class)注解,但是报错
解决办法:将porm.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>

```java 

除掉标签exclusions下的所有内容到如下:

<dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-test</artifactId>
       <scope>test</scope>
</dependency>

更多推荐