我有一个项目结构:如何从罐子中运行JUnit测试,而JUnit的找不到测试类
├── main
│ ├── java
│ │ └── qbs
│ │ ├── QbsApplication.java
│ └── resources
│ ├── application.properties
|
└── test
└── java
└── qbs
└── QbsApplicationTests.java
我有mvn clean:install
和创建jar文件生成它。现在我想用命令行运行QbsApplicationTests
。 要做到这一点我已经把两个jar到一个目录:
-rw-rw-r--. 1 a a 29M 04-05 10:30 fi.qbs-0.0.1-SNAPSHOT.jar
-rw-rw-r--. 1 a a 1M 2014-12-04 junit-4.12.jar
并执行以下命令:
java -cp .:fi.qbs-0.0.1-SNAPSHOT.jar:junit-4.12.jar org.junit.runner.JUnitCore qbs.QbsApplication
不过,我不断收到以下错误
JUnit version 4.12
.E
Time: 0,003
There was 1 failure:
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [qbs.QbsApplication]
at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:102)
at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLineParseResult.java:50)
at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseResult.java:44)
at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: qbs.QbsApplication
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.junit.internal.Classes.getClass(Classes.java:16)
at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:100)
... 4 more
FAILURES!!!
Tests run: 1, Failures: 1
问题:
- 我应该如何运行
QbsApplicationTests
测试表单控制台?
编辑 我也尝试添加以下内容:
@SpringBootApplication
public class QbsApplication {
public static void main(String[] args) {
SpringApplication.run(QbsApplication.class, args);
System.out.println("Running tests!");
JUnitCore engine = new JUnitCore();
engine.addListener(new TextListener(System.out)); // required to print reports
engine.run(QbsApplicationTests.class);
}
}
到主类,但的IntelliJ口口声声说QbsApplicationTests
不能得到解决。
测试文件夹中的所有内容都不会包含在jar中。 junit测试将在jar被构建之前正常运行在Workspace中 – Jens
@Jens这应该是一个答案。 –
这不是问题的答案。问题是'怎么样?' – mCs