导入AssertJ和JUnit时出现问题[已关闭]

ubof19bj  于 2022-11-11  发布在  其他
关注(0)|答案(2)|浏览(152)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
5天前关闭。
Improve this question
我在上大学,我必须提交一个项目。我在导入Assertj和JUnit时遇到了问题。我会在下面留下一些我的问题的图片。

如果有人能帮助我,我将非常感激!谢谢!

tpgth1q7

tpgth1q71#

我不知道为什么,但有时不包括范围将使它的工作。

<dependency>
    <groupId>org.assertj</groupId>
    <artifactId>assertj-core</artifactId>
    <version>3.22.0</version>
    <!--<scope>test</scope> --> <!-- I have commented this line out and it worked -->
</dependency>
htzpubme

htzpubme2#

您需要将junit和assertj jar文件都添加到类路径中。(Intellij包含junit库,但您必须单独下载assertj,并将它们作为依赖项添加,如here所述),或者使用从中央存储库下载依赖项的构建系统,然后您可以使用get intellij to use your pom.xml(maven构建配置),因此仍然可以从IDE中运行所有内容。
一个平凡的pom可能如下所示:

<project>
  <groupId>com.mycompany</groupId>
  <artifactId>my-project</artifactId>
  <version>1.0</version>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <!-- use 3.1.0 for Java 8 projects -->
      <version>2.1.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

相关问题