我正在用springboot学习java,我不能让junit注解在我的类中工作。
当我放置@runwith(springrunner.class)或@extendwith(springextension.class)时,它甚至没有出现无法解析符号的情况,就好像我没有在pom.xml中添加依赖项一样。
我的完整pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.fquadros</groupId>
<artifactId>minhasfinancas</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>minhasfinancas</name>
<description>Projeto para gerenciamento de finanças pessoais</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.5</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<!-- Dependencia para poder rodar testes feitos em Junit 4 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
我正在使用ide:intelij 2018.2.8
我想做的是:
添加依赖项之后,我转到了build/rebuild项目。
在终端,我已经运行了 mvn clean
以及 mvn install
命令。
在安装时,我遇到了几个错误:
https://codepen.io/flavionfg/full/kkaqvbg
我还需要做些什么来使用junit吗?
1条答案
按热度按时间huwehgph1#
而不是跑步
mvn clean
然后mvn install
,试着先跑mvn clean compile
下载依赖项并编译项目。另外要提到的是,如果您计划支持JUnit4测试,您应该添加
junit-vintage-engine
依赖关系,如junit-jupiter-engine
用于运行JUnit5测试。您可以在这里阅读更多内容:https://junit.org/junit5/docs/current/user-guide/#overview-junit-5是什么