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

Forbid usage of static inner test classes in TestNG #11316

Merged

Conversation

grantatspothero
Copy link
Contributor

@grantatspothero grantatspothero commented Mar 3, 2022

Description

TestNG support for static inner test classes is poor

Adds a TestNG listener to fail if a test class is defined as a static inner class

Related issues, pull requests, and links

This PR introduced usage of static inner test classes in kudu:
#10940

This PR subsequently removed the static inner test classes after some tests were not being run:
#11185

Documentation

(X) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

(X) No release notes entries required.
( ) Release notes entries required with the following suggested text:

@cla-bot cla-bot bot added the cla-signed label Mar 3, 2022
@grantatspothero grantatspothero force-pushed the gn/ForbidStaticInnerTestClasses branch from 56cca63 to d2985c6 Compare March 3, 2022 22:41
@grantatspothero grantatspothero changed the title Forbid usage of static inner test classes in testNG Forbid usage of static inner test classes in TestNG Mar 3, 2022
}

@VisibleForTesting
public static Optional<Class<?>> performActionIfInnerClass(Class<?> testClass, Consumer<Class<?>> consumer)
Copy link
Member

Choose a reason for hiding this comment

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

static boolean isInnerClass(Class<?> testClas)

* Detects test classes which are defined as static inner classes
* TestNG support is poor for these static inner test classes: https://github.com/trinodb/trino/pull/11185
*/
public class ReportStaticInnerTestClasses
Copy link
Member

Choose a reason for hiding this comment

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

Remove "Static", it doesn't matter.

Comment on lines 24 to 38
@Test
public void testInvalid()
{
assertThat(getEnclosingClass(TestClassWithInnerTestClasses.TestInnerTestClass.class))
.isPresent()
.contains(TestClassWithInnerTestClasses.class);

assertThat(getEnclosingClass(TestClassWithMultipleInnerTestClasses.TestInnerTestClassOne.class))
.isPresent()
.contains(TestClassWithMultipleInnerTestClasses.class);

assertThat(getEnclosingClass(TestClassWithMultipleInnerTestClasses.TestInnerTestClassTwo.class))
.isPresent()
.contains(TestClassWithMultipleInnerTestClasses.class);
}
Copy link
Member

Choose a reason for hiding this comment

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

The tested method is one-liner "is inner class". I don't think this test adds any value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to prove to myself the automation works, I can remove the MultipleInnerTestClasses cases but I think keeping at least the first testcase is helpful.

Copy link
Member

Choose a reason for hiding this comment

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

if/once you apply https://github.com/trinodb/trino/pull/11316/files#r819513710, there is nothing this test actually tests.

@grantatspothero grantatspothero force-pushed the gn/ForbidStaticInnerTestClasses branch 2 times, most recently from aa8893c to 689bdb5 Compare March 14, 2022 19:18
TestNG support for inner test classes is poor, see this issue:
trinodb#11185
@hashhar hashhar force-pushed the gn/ForbidStaticInnerTestClasses branch from 689bdb5 to 1dc1814 Compare March 15, 2022 06:12
@hashhar hashhar merged commit e0cf4a9 into trinodb:master Mar 16, 2022
@github-actions github-actions bot added this to the 374 milestone Mar 16, 2022
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.

3 participants