简体   繁体   English

如何使用gradle打包测试并从命令行运行?

[英]How to package tests with gradle and run from command line?

I have a large code base built with gradle to a fatjar. 我有一个用gradle到fatjar的大型代码库。 I have several JUnit tests which run when building. 我有几个在构建时运行的JUnit测试。

The jar & resources will be provided to a 3rd party on an isolated system, which does not have gradle and the ability to build the whole code base (and run the test goal). jar和资源将提供给隔离系统上的第3方,该系统没有gradle且不能构建整个代码库(并运行测试目标)。

Question: How can I provide my tests with the jar, and allow them to be run from command line like running a jar? 问题:如何为jar提供测试,并允许它们像运行jar一样从命令行运行?

I can't find anything on SO about distributing tests using gradle, and all the command line JUnit examples are insufficient because they require manually entering the classpath and the number of dependencies is enormous (hence use of gradle + fatjar). 我在SO上找不到任何有关使用gradle分发测试的信息,并且所有命令行JUnit示例都不足够,因为它们需要手动输入类路径并且依赖项数量巨大(因此使用gradle + fatjar)。

While searching for a similar problem, I came across http://mrhaki.blogspot.com/2010/11/gradle-goodness-create-jar-artifact.html My modifications are as follow: 在寻找类似问题时,我遇到了http://mrhaki.blogspot.com/2010/11/gradle-goodness-create-jar-artifact.html我的修改如下:

task testJar(type: Jar, dependsOn:[testClasses]) {
    from sourceSets.test.output.classesDir
}

You might want to continue from there. 您可能要从那里继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在没有软件包的Windows上从命令行运行Junit测试? - How to run Junit tests from command line on windows with no package? 如何从命令行运行springmvc + gradle项目? - How to run a springmvc+gradle project from command line? 如何在Mac bash上从命令行运行Gradle - How to run Gradle from the command line on Mac bash 如何从命令行运行单个gradle任务 - How to run a single gradle task from command line 如何从命令行运行测试? (IntelliJ Idea + Java + TestNG) - How to run tests from the command line ? (IntelliJ Idea + Java +TestNG) 如何从命令行而不是 Intellij IDEA 运行 JUnit 测试? - How to run JUnit tests from the command line instead of Intellij IDEA? 如果类在软件包中,如何从命令行运行JUnit测试? - How to run JUnit tests from the command line if classes are in packages? 如何从命令行在JUnit 4中运行也被忽略的测试? - How to run also ignored tests in JUnit 4 from command line? 您是否可以从命令行在包中运行所有JUnit测试而无需明确列出它们? - Can you run all JUnit tests in a package from the command line without explicitly listing them? 在命令行中指定的包中运行所有TestNG测试 - Run all TestNG tests in a package specified on the command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM