【问题标题】:"package org.junit does not exist" when running first time第一次运行时出现“包 org.junit 不存在”
【发布时间】:2020-09-26 18:21:48
【问题描述】:

我正在做一个小学校项目。每当我从 Git 获取代码时,第一次运行时会出现以下错误:

"package org.junit does not exist" 
"package org.junit.runners does not exist"
"cannot find symbol"

当我第二次运行该项目时,一切正常。这很烦人,因为我想在 Jenkins 中运行项目,并从 Git 导入源代码,所以它必须第一次工作。

我在 Eclipse 中检查了我的构建路径,但 JUnit5 从一开始就包含在内。 我不知道我的 pom 是否有问题,据我所知,一切似乎都很好。

<dependencies>
    <!-- Selenium dependencies -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>5.6.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.25</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>3.0.0-M4</version>
        <type>maven-plugin</type>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.7</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <configuration>
                <parallel>all</parallel>
                <threadCount>10</threadCount>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.0.0</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.1.0</version>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.2</version>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>13</source>
                <target>13</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
        </plugin>
        <plugin>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.2</version>
        </plugin>
        <plugin>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.8.2</version>
        </plugin>
        <plugin>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.7.1</version>
        </plugin>
    </plugins>
</build>

【问题讨论】:

  • 首先从 maven-surefire-plugin 配置中移除 junit-platform-surefire-provider。升级到 2.22.2 至少进一步更改代码中的导入,因为它必须是 org.junit.jupiter.api.test 等,并且 JUnit Jupiter 中不再存在 junit 跑步者。删除依赖maven-surefire-report-plugin ...

标签: git maven junit junit5


【解决方案1】:

我自己的问题已经解决了。

在 Merge 之后,一位同事添加了一些测试,这些测试是在旧版本的 JUnit 中配置的。这就是它失败的原因。将 JUnit 4 添加到我的 POM 后,我的问题就解决了。将测试更新到 JUnit 5n 也应该可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-20
    • 2021-04-05
    • 2018-05-06
    • 1970-01-01
    • 2017-08-21
    • 2017-11-01
    • 2020-10-23
    • 2015-06-27
    相关资源
    最近更新 更多