“在 Spring Boot 2.x 中应用JUnit 4.x 进行单元测试”的版本间的差异

来自姬鸿昌的知识库
跳到导航 跳到搜索
第12行: 第12行:
 
             <artifactId>junit</artifactId>
 
             <artifactId>junit</artifactId>
 
         </dependency>
 
         </dependency>
 +
</syntaxhighlight>
 +
 +
 +
 +
 +
=== BaseTest.java ===
 +
<syntaxhighlight lang="java">
 +
package org.example;
 +
 +
import org.junit.runner.RunWith;
 +
import org.springframework.boot.test.context.SpringBootTest;
 +
import org.springframework.test.context.junit4.SpringRunner;
 +
 +
@RunWith(SpringRunner.class)
 +
@SpringBootTest(classes = Application.class)
 +
public class BaseTest {
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>

2023年1月28日 (六) 22:42的版本

pom.xml

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


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>



BaseTest.java

package org.example;

import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class BaseTest {
}