简体   繁体   中英

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. 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. 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 . You can then get intellij to use your pom.xml (maven build configuration), so everything can still be run from within your IDE.

A trivial pom might be something like the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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