Java 尝试执行junit测试时出错
我试图运行一些junit测试,但我经常出错 MyJava 尝试执行junit测试时出错,java,maven,intellij-idea,junit,junit5,Java,Maven,Intellij Idea,Junit,Junit5,我试图运行一些junit测试,但我经常出错 Mypom.xml具有以下maven依赖项: <junit.version>4.12</junit.version> <junit.jupiter.version>5.0.1</junit.jupiter.version> <junit.vintage.version>${junit.version}.1</junit.vintage.version> <junit.plat
pom.xml
具有以下maven依赖项:
<junit.version>4.12</junit.version>
<junit.jupiter.version>5.0.1</junit.jupiter.version>
<junit.vintage.version>${junit.version}.1</junit.vintage.version>
<junit.platform.version>1.0.1</junit.platform.version>
<!-- junit dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<!-- Only required to run tests in an IDE that bundles an older version -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
</dependency>
<!-- To avoid compiler warnings about @API annotations in JUnit code -->
<dependency>
<groupId>org.apiguardian</groupId>
<artifactId>apiguardian-api</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
我正在使用IntelliJ IDEA 2016.3.5
我在谷歌上搜索了一下,但没有找到任何好的回复,没有任何想法?我已经从您提供的链接下载了该项目。当我将
add
方法更改为public
时,一切正常:
@Test
public void add() {
Calculator calculator = new Calculator();
assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2");
}
我尝试从IDE和maven运行测试。要从maven运行测试,您可以尝试在命令行中执行以下命令:
mvn clean install
这将为您构建项目并运行测试
我的设置是:
- Java版本:“1.8.0_131”
- Maven版本:3.3.9
- IntelliJ idea版本(如果您想从IDE运行测试,可能会很有用):2017.2.5
add
方法更改为public
时,一切正常:
@Test
public void add() {
Calculator calculator = new Calculator();
assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2");
}
我尝试从IDE和maven运行测试。要从maven运行测试,您可以尝试在命令行中执行以下命令:
mvn clean install
这将为您构建项目并运行测试
我的设置是:
- Java版本:“1.8.0_131”
- Maven版本:3.3.9
- IntelliJ idea版本(如果您想从IDE运行测试,可能会很有用):2017.2.5