在 Junit5 中执行测试类时出现“未找到测试错误”

时间:2021-01-22 09:28:46

标签: intellij-idea junit5

以下是我在 Intellij Idea maven 项目中使用的 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>code</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
    </properties>

        <dependencies>

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

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
            </plugin>
        </plugins>
    </build>
</project>

一切正常。但是当我运行包含@Test 注释的测试文件时。
我得到 No tests were found error

这是测试类:

package com.lab1;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class PascalTriangleTests {
    @Test
    private void test(){
        PascalTriangle pascalTriangle = new PascalTriangle();
        pascalTriangle.generate(1);
        assertEquals(pascalTriangle.getPascalTriangle().size(),1,"It should be one");
    }
}

这个类如果由于某种原因运行它不会运行测试功能

1 个答案:

答案 0 :(得分:1)

删除 private 修饰符 - 在测试方法中是不允许的。

相关问题