简体   繁体   中英

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

I have a large code base built with gradle to a fatjar. I have several JUnit tests which run when building.

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).

Question: How can I provide my tests with the jar, and allow them to be run from command line like running a 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).

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:

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

You might want to continue from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM