Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It does not work for gradle to execute specific tests from the command-line

For gradle, executing specific tests from the command-line should work since version 1.0 (or 1.1), but it does not work on version 2.7.

I tried below commands:

gradle test --tests com.mk.myfirstapp.MyUT

gradle outputs 'unknown cmdline options':

FAILURE: Build failed with an exception.

* What went wrong:
Problem configuring task :app:test from command line.
> Unknown command-line option '--tests'.

* Try:
Run gradle help --task :app:test to get task usage details. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.505 secs

The same for another command like

gradle -Dtest.single=abc test

Does anyone know it is a bug or my misuse? Thanks.

more details

I did the same as Opel(below), but I have a difference result. What is wrong with my gradle then :-?


mk@mk-desktop:~/StudioProjects/MyFirstApp$ gradle -v

------------------------------------------------------------
Gradle 2.7
------------------------------------------------------------

Build time:   2015-09-14 07:26:16 UTC
Build number: none
Revision:     c41505168da69fb0650f4e31c9e01b50ffc97893

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_51 (Oracle Corporation 25.51-b03)
OS:           Linux 3.5.0-44-generic amd64

mk@mk-desktop:~/StudioProjects/MyFirstApp$ gradle test --tests BlogFeedEndpointSpec 
WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.json:json:20150407-jdk16 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.1 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.5.1 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.json:json:20150407-jdk16 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage with jarjar to change the class packages

FAILURE: Build failed with an exception.

* What went wrong:
Problem configuring task :app:test from command line.
> Unknown command-line option '--tests'.

* Try:
Run gradle help --task :app:test to get task usage details. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 3.574 secs
like image 626
MK at Soho Avatar asked Nov 06 '15 14:11

MK at Soho


People also ask

How do I run a Gradle test in command line?

Use the command ./gradlew test to run all tests.

How do I run a specific test class in Gradle?

In Gradle, we can pass an --tests option to run a single unit test class.


1 Answers

--tests option is correctly recognized in gradle 2.7:

➜  backend git:(master) gradle -v

------------------------------------------------------------
Gradle 2.7
------------------------------------------------------------

Build time:   2015-09-14 07:26:16 UTC
Build number: none
Revision:     c41505168da69fb0650f4e31c9e01b50ffc97893

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_05 (Oracle Corporation 25.5-b02)
OS:           Mac OS X 10.10.4 x86_64

➜  backend git:(master) gradle test --tests BlogFeedEndpointSpec 
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [BlogFeedEndpointSpec]

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 6.88 secs
like image 77
Opal Avatar answered Nov 11 '22 13:11

Opal