Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listing tests from the CLI (--list-tests) #2129

Closed
staffanf opened this issue May 23, 2017 · 21 comments
Closed

Listing tests from the CLI (--list-tests) #2129

staffanf opened this issue May 23, 2017 · 21 comments
Assignees
Labels
a:feature A new functionality in:console output progress tty mintty cygwin cli in:testing
Milestone

Comments

@staffanf
Copy link

I would like to have a CLI option similar to the "--tests=*SomethingTest" that only lists the tests available for a Test task without actually running them.

Expected Behavior

./gradlew test --list-tests="com.stuff.*" should list all tests that would have been run by the test task under the com.stuff package.
./gradlew test --list-tests="*StuffTest" should list all tests that would have been run by the test task in StuffTest named classes in any package.
./gradlew integTest --list-tests should list all tests that would have been run by the integTest task.

This should be similar to the --tests switch only with the added change of not actually running any tests.

Current Behavior

There is no way to only list tests in gradle today that I know of.

Context

We typically have long-running integrationTest tasks. I typically run a subset of these tests on my local machine and do not always know the exact name of the test I want to run. Currently I have to go into the source code to find the right tests. This could be replaced with a couple of quick CLI commands and perhaps grep.

@eriwen
Copy link
Contributor

eriwen commented May 25, 2017

It'd also be awesome to have this for gradle-completion

@eriwen eriwen added a:feature A new functionality from:contributor in:console output progress tty mintty cygwin cli in:testing labels May 25, 2017
@MartinHaeusler
Copy link

I think this feature would be very useful. I just stumbled upon this issue via google, as this was just the thing I was looking for.

My use case is to test whether my include and exclude statements work as intended.

@ror6ax
Copy link

ror6ax commented Nov 19, 2018

This would be one awesome feature.

@HuangLED
Copy link

+1 this feature would be nice

@thigg
Copy link

thigg commented Jul 31, 2019

+1

1 similar comment
@FLXT-Qi
Copy link

FLXT-Qi commented Nov 7, 2019

+1

@ghost
Copy link

ghost commented Nov 21, 2019

+1 for the same reason as @MartinHaeusler

@rkrisztian
Copy link

You could just use an IDE to find the classes you need.

@quidryan
Copy link
Contributor

Another use-case: once tests are exposed via the CLI (or an API), external tools can partition the tests and run them on separate nodes. Each partition could be fed back into Gradle using --tests.

@msilb
Copy link

msilb commented Apr 29, 2020

Is there any update on this feature request? As previously mentioned by @quidryan this feature would be super useful for slicing test workload across build machines in a CI/CD environment.

@ljacomet ljacomet added the @jvm label May 18, 2020
@XenonLX
Copy link

XenonLX commented May 29, 2020

Stumbled upon the same issue, we need to discover a set of tests required for further execution in distributed mode, when each thread is represented by the separate host, for this, we need these names to be compatible with filtering pattern for execute via "--tests=org.smth.SomeTestName", we also expect it to work with BDD tests.

jaycarlton referenced this issue in all-of-us/workbench Jun 9, 2020
@slonka
Copy link

slonka commented Sep 1, 2020

We need the same feature for test splitting. Right now the only solution is compiling the project, assuming tests are named ./**/*Test.* and some bash hacking. (if interested see: https://github.com/allegro/envoy-control/blob/run-tests-in-parallel-3/.circleci/config.yml#L55 https://github.com/allegro/envoy-control/blob/run-tests-in-parallel-3/run-tests-in-files.sh)

@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you're interested in how we try to keep the backlog in a healthy state, please read our blog post on how we refine our backlog. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.

@stale stale bot added the stale label Apr 16, 2022
@staffanf
Copy link
Author

At the moment, I'm not using Gradle very, although I which I was.
I still would like this 6th most voted issue to stay open so when I come back, I might reap the benefits.

@kennknowles
Copy link

👍

@siilike
Copy link

siilike commented Mar 4, 2023

task tests {
	doLast {
		def testExecutionSpec = tasks.getByName("test") as Test

		def processor = new org.gradle.api.internal.tasks.testing.TestClassProcessor() {
			void startProcessing(org.gradle.api.internal.tasks.testing.TestResultProcessor processor) {}
			void stop() {}
			void stopNow() {}

			void processTestClass(org.gradle.api.internal.tasks.testing.TestClassRunInfo info) {
				println(info.getTestClassName())
			}
		}

		def detector = new org.gradle.api.internal.tasks.testing.detection.DefaultTestClassScanner(testExecutionSpec.getCandidateClassFiles(), testExecutionSpec.getTestFramework().getDetector()?.tap {
			setTestClasses(testExecutionSpec.getTestClassesDirs().getFiles())
			setTestClasspath(Collections.unmodifiableSet(testExecutionSpec.getClasspath().getFiles()))
		}, processor)

		detector.run()
	}
}

@rkrisztian
Copy link

@siilike, sadly internal API is prone to changes, that solution might not survive for long.

@sschuberth
Copy link
Contributor

Something like this could be achieved by combining --tests with --dry-run (and eventually grep'ing the output).

@MartinHaeusler
Copy link

Any news on this matter? The JUnit test filters in gradle are really finicky in my experience, I'm having a hard time configuring them. Our integration test suite takes roughly 30 minutes for a full run and involves thousands of test cases, a trial-and-error approach in configuring the filters just isn't realistic with a cycle time as long as this.

bot-gradle added a commit that referenced this issue Jun 14, 2023
See the linked issue #2129 Created this PR to discuss the solution in async manner and discover an issues

Now the idea is user will get the result of dry run as a usual in xml/html test report

Co-authored-by: Sergey Opivalov <sopivalov@gradle.com>
@6hundreds
Copy link
Member

Will be shipped in 8.3

@sschuberth
Copy link
Contributor

Here's the docs: https://docs.gradle.org/8.3-rc-1/release-notes.html#dry-run-mode-for-test-execution 🙌🏻

@ov7a ov7a added this to the 8.3 milestone Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:feature A new functionality in:console output progress tty mintty cygwin cli in:testing
Projects
None yet
Development

No branches or pull requests