-
Notifications
You must be signed in to change notification settings - Fork 130
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
Fixes @LocalData
when being used on a test method in superclass
#907
Conversation
By switching to `getDeclaredMethod` in jenkinsci#900, this broke this use case that is currently exercised in email-ext plugin (`ScriptContentSecureTest>ScriptContentTest#testTemplateShouldBeLoadedFromTheClosestExistingFolderConfigInTheHierarchyUpToGlobalConfig`)
/** | ||
* Illustrates a case where a test class extends another test class that has test methods using the LocalData recipe. | ||
*/ | ||
public class LocalDataExtendedTest extends LocalDataZipTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to confirm this is intended not to have any test inside it and it fails without the change in src/main
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the purpose is for it to pick up the test method defined in LocalDataZipTest
to demonstrate the problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vlatombe Sorry for the inconvenience, I was unaware of that use case being used. Please see my comment below.
@@ -102,7 +102,7 @@ public void setup(JenkinsRule jenkinsRule, LocalData recipe) throws Exception { | |||
Method testMethod; | |||
|
|||
try { | |||
testMethod = desc.getTestClass().getDeclaredMethod(desc.getMethodName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work for JUnit5 tests that do not have a JenkinsRule as parameter (which is a valid option) and are not public (which is also a valid option).
One remedy would be to use both getMethod
and getDeclaredMethod
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok. Got misleaded by the existing tests that were still passing and didn't go further. I guess we'll need both indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that do not have a JenkinsRule as parameter (which is a valid option)
How is that valid? @LocalData
is expected to work within a JenkinsRule instance, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is, however you can do something like this:
@WithJenkins
class TestClass {
private JenkinsRule rule;
@BeforeEach
void before(JenkinsRule rule) {
this.rule = rule;
}
@LocalData
@Test
void testMethod() {
// do stuff with rule
}
}
By switching to
getDeclaredMethod
in #900, this broke this use case that is currently exercised in email-ext plugin(
ScriptContentSecureTest>ScriptContentTest#testTemplateShouldBeLoadedFromTheClosestExistingFolderConfigInTheHierarchyUpToGlobalConfig
)The provided test breaks without this patch.
Testing done
Submitter checklist