Skip to content

Conversation

@crogoz
Copy link
Contributor

@crogoz crogoz commented Nov 19, 2025

Before this PR

After this PR

FLUP for https://pl.ntr/2ye. We can now auto-discover the testClasesFiles in a repo using a DiscoveryTestClassesTask task. Introducing 2 tasks:

  1. discoverGradlePluginTests discovers GradlePluginTests annotated test classes. This will be used by the Configuration cache enablement migration to discover the tests that need to be annotated with @DisabledConfigurationCache.
  2. discoverNebulaTestClassesToMigrate discovers the groovy test classes that extend IntegrationSpec, IntegrationTeskKitSpec excluding the ConfigurationCacheSpec tests. This will be used by the excavator to discover the groovy tests that need to be migrated to the new junit framework.

==COMMIT_MSG==
[DiscoveryTestClassesTask] Task that discovers testClasses in spock and junit-jupiter test engines
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Nov 19, 2025

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

[DiscoveryTestClassesTask] Task that discovers testClasses in spock and junit-jupiter test engines

Check the box to generate changelog(s)

  • Generate changelog entry

@changelog-app
Copy link

changelog-app bot commented Nov 19, 2025

Successfully generated changelog entry!

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.


📋Changelog Preview

💡 Improvements

  • [DiscoveryTestClassesTask] Task that discovers testClasses in spock and junit-jupiter test engines (#297)

.assertThat()
.content()
.isEqualTo("src/test/java/test/GradlePluginTestClass.java");
assertThat(Files.readAllLines(rootProject

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's make a static method for:

Files.readAllLines(rootProject.buildDir().directory("tests-discovery/java").file("test-classes-paths").path());

e.g. readTestClassesPaths or something

Comment on lines 32 to 35
@Option(names = "--include", split = ",", description = "List of subClasses to include")
private List<String> subClasses;
private List<String> classNames;

@Option(names = "--exclude", split = ",", description = "List of subClasses to exclude")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's update the description with the new change

return annotations.stream().anyMatch(annotation -> hasClassAnnotation(clazz, annotation));
}

private static boolean hasClassAnnotation(Class<?> clazz, String annotationName) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something I forgot to mention the first time. We should use AnnotationSupport#isAnnotated it's in the junit-platform-commons jar


@Override
protected Filter<?> getFilter() {
return new PostDiscoveryFilter() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we convert the list of includedAnnotations to List<Class<? extends Annotation>> here, and then reference that below?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we won't pay the cost of loading the class each time, since it's cached within the classloader, but there's still a bit of code around that which scales with the number of tests a project has.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want to just filter here rather than throw? then you don't fail when you try to run this command on a classpath that doesn't have the annotations you care about. That said, I'm not sure if it will happen in practice

@felixdesouza
Copy link

👍 let's gooo 🚀

@bulldozer-bot bulldozer-bot bot merged commit 9243192 into develop Nov 26, 2025
5 checks passed
@bulldozer-bot bulldozer-bot bot deleted the cr/discover-tests branch November 26, 2025 10:55
@autorelease3
Copy link

autorelease3 bot commented Nov 26, 2025

Released 0.40.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants