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

Report unannotated JUnit Test annotation #18691

Closed
wants to merge 1 commit into from

Conversation

ebyhr
Copy link
Member

@ebyhr ebyhr commented Aug 16, 2023

Description

Fixes #14027

Release notes

(x) This is not user-visible or is docs only, and no release notes are required.

@@ -28,10 +27,10 @@ private Listeners() {}
/**
* Print error to standard error and exit JVM.
*
* @apiNote A TestNG listener cannot throw an exception, as this are not currently properly handled by TestNG.
* @apiNote A TestNG listener and JUnit extension cannot throw an exception, as this are not currently properly handled by them.
Copy link
Member

Choose a reason for hiding this comment

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

This class is in testng.services package. let's move to io.trino.testing


private static boolean overriddenMethodHasTestAnnotation(Method method)
{
if (method.isAnnotationPresent(Test.class)) {
Copy link
Member

Choose a reason for hiding this comment

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

fully qualified name would be better here. there are more than 1 @Test  candidates

Comment on lines 99 to 100
if (method.getDeclaringClass().isInterface()) {
return false;
Copy link
Member

Choose a reason for hiding this comment

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

why? explain

return false;
}

for (Class<?> interfaceClass : method.getDeclaringClass().getInterfaces()) {
Copy link
Member

Choose a reason for hiding this comment

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

Why look at interfaces? please explain

@@ -0,0 +1 @@
io.trino.testng.services.ReportBadJunitTestAnnotations
Copy link
Member

Choose a reason for hiding this comment

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

not under testng -- io.trino.testing.junit or just io.trino.junit

Comment on lines 78 to 81
private static boolean isUnannotated(Method method)
{
return Arrays.stream(method.getAnnotations()).map(Annotation::annotationType)
.anyMatch(ReportBadJunitTestAnnotations::isJUnitAnnotation);
Copy link
Member

Choose a reason for hiding this comment

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

isUnannotated = ... anyMatch(isJUnitAnnotation)

was noneMatch meant? or was the method be named isAnnotated?

@ebyhr ebyhr marked this pull request as ready for review August 17, 2023 06:22
{
return Arrays.stream(realClass.getMethods())
.filter(method -> method.getDeclaringClass() != Object.class)
.filter(method -> !Modifier.isStatic(method.getModifiers()))
Copy link
Member

Choose a reason for hiding this comment

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

Static methods are not overridden, so this should be handled by the overriddenMethodHasTestAnnotation logic below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Disagreed. There's no benefit to delay the filter.

@@ -0,0 +1 @@
junit.jupiter.extensions.autodetection.enabled=true
Copy link
Member

Choose a reason for hiding this comment

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

@@ -0,0 +1 @@
io.trino.junit.ReportBadJunitTestAnnotations
Copy link
Member

Choose a reason for hiding this comment

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

This is very brittle. It only works if a module depends on trino-testing-services. To ensure it applies to everything, the extension should be registered via the surefire plugin configuration. It may require moving this check out of the project, and building an artifact that the Trino build can depend on.

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 know, but it's much better than no reporter.

Copy link
Member

Choose a reason for hiding this comment

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

@martint would you like to provide this safety? Without this we are risking that some tests are not executed and IMHO this is a blocker for further migration to JUnit.

@ebyhr
Copy link
Member Author

ebyhr commented Aug 21, 2023

Closing as I have no bandwidth for converting to maven plugin.

@ebyhr ebyhr closed this Aug 21, 2023
@ebyhr ebyhr deleted the ebi/test-junit branch August 21, 2023 23:56
@martint
Copy link
Member

martint commented Aug 22, 2023

It doesn't need to be a maven plugin -- just a library that can be included in the plugin configuration for the whole project.

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

Successfully merging this pull request may close these issues.

Add checker for JUnit @Test annotation in overridden tests
4 participants