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.