java 在 Jenkins 中自动运行 JUnit 测试,无需 maven 或 ant

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16669507/
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 23:36:13  来源:igfitidea点击:

Run JUnit tests automatically in Jenkins without maven or ant

javaunit-testingjunitjenkinscontinuous-integration

提问by Bosion

I am currently setting up a continuous integration tool with Jenkins. I would like to run JUnit tests everytime a build is made. My problem is that none of the projects that will be tested use maven or ant. So I would like to know if it is possible to run these tests without maven or ant, and if it is, how do I do it ?

我目前正在与 Jenkins 建立一个持续集成工具。我想在每次构建时运行 JUnit 测试。我的问题是将要测试的项目都没有使用 maven 或 ant。所以我想知道是否可以在没有 maven 或 ant 的情况下运行这些测试,如果可以,我该怎么做?

Thank you in advance for your answers

预先感谢您的回答

采纳答案by Matthew Farwell

Have you tried ClasspathSuiteby Johannes Link?

您是否尝试过 Johannes Link 的ClasspathSuite

From the documentation:

从文档:

The mechanism is simple. Just create a new project in Eclipse and add all projects that contain tests you want to run to its build path. Now create a class like that:

import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.runner.RunWith;
@RunWith(ClasspathSuite.class)
public class MySuite {}

This will execute all JUnit4 testclasses (those containing methods with the @Test annotation) in the projects classpath.

机制很简单。只需在 Eclipse 中创建一个新项目,并将包含要运行的测试的所有项目添加到其构建路径。现在创建一个这样的类:

import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.runner.RunWith;
@RunWith(ClasspathSuite.class)
public class MySuite {}

这将执行项目类路径中的所有 JUnit4 测试类(那些包含带有 @Test 注释的方法)。

You can then run it using JUnitCore.

然后您可以使用JUnitCore运行它。

java -cp /usr/share/java/junit.jar org.junit.runner.JUnitCore [test class name]

For more information, see How to run Junit testcases from command line?.

有关更多信息,请参阅如何从命令行运行 Junit 测试用例?.