我决定今天早上通过试用版试用IntelliJ并安装了JUnit插件.我创建了一个新的Java项目,我想为它编写一个测试用例.
如何将junit.jar文件添加到项目中?(我实际上想将它添加到每个java项目中,现在和永远更多 - 有没有办法做到这一点?).
我在SO上找到的最接近的帖子是:为什么我得到"无法解析符号"?
但它没有帮助我.:(
这是我的错误截图:
我确保我的pom.xml是作用域的,我的实际代码也放在测试文件夹下.这是我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.fishercoder</groupId>
<artifactId>leetcode-algorithms</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
也
mvn clean compile
Run Code Online (Sandbox Code Playgroud)
运行成功.
这是结果
mvn test
Run Code Online (Sandbox Code Playgroud)
这里:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.stevesun.AddBinaryTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.042 sec
Running com.stevesun.MissingRangesTest
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, …
Run Code Online (Sandbox Code Playgroud)