SpringBoot测试类不需要加@RunWith?

# 在idea中,自动生成的测试类没有@RunWith运行正常?

在SpringBoot2.2.0以前是JUnit4,在SpringBoot之后是JUnit5。

Juint版本说明

Junit4

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

Junit5

<dependency>
  <groupId>org.junit.jupiter</groupId>
  <artifactId>junit-jupiter</artifactId>
  <version>5.6.2</version>
  <scope>test</scope>
</dependency>

测试方法:

public class TestDemo {
    @Test
    void function(){
        System.out.println("test function");
    }
}

对于Junit4而言,所有的测试方法应当是public声明的,而Junit5不用。只不过不同的版本,这个@Test的类是不同的:

Junit4: org.junit.Test
Junit5: org.junit.jupiter.api.Test

 

 

 

 

 

 

 

 

 

 


版权声明:本文为qq_31832209原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。