java 在一个 jar 中运行 Junit 测试类,在 jar 外运行 junit

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14537233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 16:35:47  来源:igfitidea点击:

Run Junit test class inside one-jar with junit outside the jar

javacommand-linejarjunitexecutable-jar

提问by Mr_and_Mrs_D

So I have packed my classes and their dependancies (apache commons cli) inside a jar file using one-jar(which was easy enough to do, see section Command-Line Approach). Now I am curious if I can run the java test class inside the jar using a Junit jar outside the class. So the path to the test class inside sw.jaris :

因此,我使用one-jar将我的类及其依赖项(apache commons cli)打包在一个 jar 文件中(这很容易做到,请参阅命令行方法部分)。现在我很好奇是否可以使用类外的 Junit jar 在 jar 内运行 java 测试类。所以里面测试类的路径sw.jar是:

sw.jar\main\sw.jar\uoa\di\ys11\hw2\TestSmithWaterman.class

(the main\is a one-jar thing). I have tried variations of :

(这main\是一个一罐的东西)。我尝试过以下变体:

java -jar -cp lib/junit.jar org.junit.runner.JUnitCore  uoa.di.ys11.hw2.TestSmithWaterman

with no luck - so what would the command line be ? Or do I need to modify the one-jar manifest somehow ?

没有运气 - 那么命令行是什么?或者我是否需要以某种方式修改单罐清单?

EDIT : the /boot-manifest.mf:

编辑:/boot-manifest.mf

Manifest-Version: 1.0
Main-Class: com.simontuffs.onejar.Boot
One-Jar-Main-Class: uoa.di.ys11.hw2.Hw2

while the /META-INF/MANIFEST.MF:

/META-INF/MANIFEST.MF

Manifest-Version: 1.0
Created-By: 1.7.0_09 (Oracle Corporation)
Main-Class: com.simontuffs.onejar.Boot
One-Jar-Main-Class: uoa.di.ys11.hw2.Hw2

采纳答案by Roman C

Use the following command line to test

使用以下命令行进行测试

java -cp lib/junit.jar;sw.jar org.junit.runner.JUnitCore  uoa.di.ys11.hw2.TestSmithWaterman

EDIT:

编辑:

this should be work with normal jars, but the jar is created by the one-jar

这应该适用于普通罐子,但罐子是由一个罐子创建的

One-JAR lets you package a Java application together with its dependency Jars into a single executable Jar file.

One-JAR 允许您将 Java 应用程序与其依赖项 Jar 一起打包到单个可执行 Jar 文件中。

After that it's not possible for junit, as I mention junit-4.4 in my case to load such classes for test.

在那之后,junit 就不可能了,正如我在我的例子中提到的 junit-4.4 加载这样的类进行测试。