简体   繁体   English

导入 AssertJ 和 JUnit 时的问题

[英]Problems when importing AssertJ and JUnit

I'm at university and I have to submit a project.我在大学,我必须提交一个项目。 I'm having problems with Assertj and JUnit when importing.我在导入时遇到了 Assertj 和 JUnit 问题。 I'll leave below some images of my problem.我将在下面留下一些我的问题的图片。

在此处输入图像描述

I'll really appreciate if someone could help me!如果有人可以帮助我,我将不胜感激! Thank you!谢谢!

You'll need to get both the junit and assertj jar files added to your class path.您需要将 junit 和 assertj jar 文件都添加到您的类路径中。 You can either do this within your IDE manually (Intellij includes the junit library, but you'll have to download assertj seperately and add them as dependencies as outlined here ), or by using a build system that downloads dependencies from a central repository, like maven .您可以在 IDE 中手动执行此操作(Intellij 包含 junit 库,但您必须单独下载 assertj 并将它们添加为此处概述的依赖项),或者使用从中央存储库下载依赖项的构建系统,例如行家 You can then get intellij to use your pom.xml (maven build configuration), so everything can still be run from within your IDE.然后,您可以让 intellij 使用您的pom.xml (maven 构建配置),因此仍然可以在您的 IDE 中运行所有内容。

A trivial pom might be something like the following:一个微不足道的 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>

I don't know why but sometimes not including scope will make it work我不知道为什么,但有时不包括范围会使其工作

<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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM