Junit 测试类为';我在Maven学的
我在SpringBoot(v2.45)项目中有一个测试类 我可以在意念中运行它,但是Junit 测试类为';我在Maven学的,junit,spring-test,Junit,Spring Test,我在SpringBoot(v2.45)项目中有一个测试类 我可以在意念中运行它,但是 mvn test 因为某种原因,我不会运行它 测试类使用JUnit4,SpringBootV2.xx使用JUnit5。我不知道这是不是一个原因。以下是测试类的导入声明: import com.hackerrank.test.utility.Order; import com.hackerrank.test.utility.OrderedTestRunner; import com.hackerrank.tes
mvn test
因为某种原因,我不会运行它
测试类使用JUnit4,SpringBootV2.xx使用JUnit5。我不知道这是不是一个原因。以下是测试类的导入声明:
import com.hackerrank.test.utility.Order;
import com.hackerrank.test.utility.OrderedTestRunner;
import com.hackerrank.test.utility.ResultMatcher;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.rules.SpringClassRule;
import org.springframework.test.context.junit4.rules.SpringMethodRule;
import org.springframework.test.web.servlet.MockMvc;
import static org.junit.Assert.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
我将以下两个与测试相关的依赖项添加到pom.xml文件中:
<dependency>
<groupId>com.hackerrank.applications</groupId>
<artifactId>junit-ordered-test-runner</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
com.hackerrank.applications
junit命令测试运行程序
1.0.0
朱尼特
朱尼特
测试
如何解决这个问题?官方文件说 如果您有使用JUnit4的测试,可以使用JUnit5的老式引擎来运行它们。要使用vintage引擎,请添加对junit vintage引擎的依赖项,如以下示例所示:
org.junit.vintage
朱尼特老式发动机
测试
org.hamcrest
汉克雷斯特岩芯
<dependency>
<groupId>com.hackerrank.applications</groupId>
<artifactId>junit-ordered-test-runner</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>