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

Retry Spock2 parameterized methods independently of the class #202

Merged
merged 4 commits into from
Jul 17, 2023

Conversation

pshevche
Copy link
Member

Summary

Previously, if Spock tests were executed using Gradle's JUnitPlatformTestFramework, we would retry an entire class if one of its parameterized methods failed. This applied both to Spock 2 tests and Spock 1 tests run with JUnit Vintage engine. However, parameterized tests cannot be retried independently only in the latter case.

This PR changes that and checks for spock-core-2* JAR on the classpath to differentiate between both cases. If the JAR is present, parameterized tests will be retried independently, otherwise, as an entire class.

@Override
public TestFramework createRetrying(TestFrameworkTemplate template, TestFramework testFramework, TestNames failedTests) {
DefaultTestFilter failedTestsFilter = testFilterFor(failedTests, false, template);
DefaultTestFilter failedTestsFilter = testFilterFor(failedTests, isSpock2Used, template);
Copy link
Member Author

Choose a reason for hiding this comment

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

💬 This boolean will be propagated ascanRunParameterizedSpockMethods to https://github.com/gradle/test-retry-gradle-plugin/blob/main/plugin/src/main/java/org/gradle/testretry/internal/executer/framework/BaseJunitTestFrameworkStrategy.java#L91 that ultimately decides how to retry parameterized test failures: as a whole class or individually.

@pshevche pshevche force-pushed the pshevche/retry_spock2_parameterized_methods branch from d7f6f53 to ade7b52 Compare July 11, 2023 14:58
} else if (testFramework instanceof TestNGTestFramework) {
return new TestNgTestFrameworkStrategy();
} else {
return null;
}
}

static boolean isSpock2Used(JvmTestExecutionSpec spec) {
Iterator<? extends File> classpathIterator = spec.getClasspath().iterator();
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ Don't we also have to check spec.getModulePath() since Spock 2 should end up there if java.modularity.inferModulePath is set to true in the build script?

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems like setting it to true is not enough. Does it have to be a similar setup as described in https://docs.gradle.org/current/samples/sample_java_modules_multi_project_with_integration_tests.html? Where the test source set is a module itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a check of module path in d06b375. But I have not managed to set up a test yet where that would happen. I can look into it once I am back.

Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
…m suffix

Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
…etried as a whole

Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
@pshevche pshevche force-pushed the pshevche/retry_spock2_parameterized_methods branch from d06b375 to 9661e8d Compare July 12, 2023 15:21
Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
@pshevche pshevche force-pushed the pshevche/retry_spock2_parameterized_methods branch from 9661e8d to e03e80d Compare July 17, 2023 07:49
@pshevche pshevche merged commit 414d60a into main Jul 17, 2023
5 checks passed
@pshevche pshevche deleted the pshevche/retry_spock2_parameterized_methods branch July 17, 2023 07:55
@marcphilipp marcphilipp added this to the 1.5.4 milestone Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants