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

Support MethodSource as custom test source in dynamic tests #1850

Closed
4 tasks done
magictractor opened this issue Apr 8, 2019 · 16 comments
Closed
4 tasks done

Support MethodSource as custom test source in dynamic tests #1850

magictractor opened this issue Apr 8, 2019 · 16 comments

Comments

@magictractor
Copy link

magictractor commented Apr 8, 2019

Background

#1467 and #1178 added support for dynamic containers and tests specifying a custom test source via DynamicNode.getTestSourceUri().

These URIs can be used to link dynamic tests and containers with a FileSource, DirectorySource or ClasspathResourceSource.

These sources may optionally have an associated line and column number, which is indicated by using a query string in the URI, such as line=23&column=12.

Proposal

If a URI has a classpath scheme and a method=myMethodName query string then TestFactoryTestDescriptor.fromUri(URI uri) should create and return a MethodSource.

Use cases

I initially encountered this when using @TestFactory to run a test suite without switching engines. That's working (bar linking back to methods in test cases from the test tree in Eclipse), but it is not a compelling use case since suites are being addressed by #744.

However, I can envisage other cases where this would be useful, such as verifying consistent use of Hibernate annotations across Java beans. Previously I've written cumbersome custom PMD rules for this. Dynamic tests could link back to getters in the application source rather than unit tests.

Related issues

Deliverables

  • ❌ Add support for creating a MethodSource for a dynamic test if the custom test source URI uses the classpath scheme and a method=myMethodName query string.
  • Introduce support for converting from a URI of the form method:<FQMN> to a MethodSource, where FQMN is the fully qualified method name. See the Javadoc for DiscoverySelectors.selectMethod(String) for the supported formats for a FQMN.
  • Modify JavaDoc to explain supported URI schemas and query strings.
  • Document in User Guide. will be addressed in Document URI TestSource support of dynamic tests in User Guide #1903
  • Document in Release Notes.
@marcphilipp
Copy link
Member

Thanks for raising the issue. I think that would make sense.

@junit-team/junit-lambda WDYT?

@marcphilipp
Copy link
Member

Tentatively assigned to 5.5 M2 for team discussion.

@marcphilipp marcphilipp added this to the 5.5 M2 milestone Apr 8, 2019
@sbrannen sbrannen changed the title Support method resource for custom test source in dynamic tests Support MethodSource as custom test source in dynamic tests Apr 12, 2019
@sbrannen
Copy link
Member

sbrannen commented Apr 12, 2019

Team Decision:

Although we do not foresee that many developers would use such a MethodSource to link to non-test methods (as in the originally listed use cases), we can imagine that such a feature could be useful for linking to methods used as a method reference and similar use cases. We have therefore decided to go ahead with this proposal modified as follows.

Introduce support for converting from a URI of the form method:<FQMN> to a MethodSource, where FQMN is the fully qualified method name. See the Javadoc for DiscoverySelectors.selectMethod(String) for the supported formats for a FQMN.

Ideally, the new method: scheme should be internal to JUnit Jupiter and not leaked into the JUnit Platform.

Note that we will not reuse the classpath: scheme since that scheme is solely for "classpath resources" which a method is not.

@sbrannen
Copy link
Member

This issue is currently "up for grabs".

@sbrannen
Copy link
Member

FYI: the implementation of this feature should internally delegate to org.junit.platform.commons.util.ReflectionUtils.parseFullyQualifiedMethodName(String) for parsing the FQMN.

@gopinath-langote
Copy link
Contributor

@sbrannen If no one is picked up this. I would like to pick this issue & submit PR.
Let me know!

@marcphilipp marcphilipp modified the milestones: 5.5 M2, 5.5 Backlog Apr 18, 2019
@sbrannen
Copy link
Member

@gopinath-langote, you're the first to volunteer. So feel free to submit a PR.

@ielatif
Copy link
Contributor

ielatif commented May 10, 2019

@gopinath-langote did you get a chance to work on this? If not, I can pick it up if you don't mind?

@marcphilipp
Copy link
Member

@ielatif Feel free to pick it up, if you're still interested.

@ielatif
Copy link
Contributor

ielatif commented May 21, 2019

@marcphilipp Yes I still do.

@sbrannen

Ideally, the new method: scheme should be internal to JUnit Jupiter and not leaked into the JUnit Platform.

We can add a new class ex: MethodFinder/MethodExtractor in org.junit.jupiter.engine.descriptor to implement the logic of extracting a method from URI Optional<Method> findMethod(URI uri)

Or may be reuse org.junit.jupiter.engine.discovery.MethodFinder and add a new method to it Optional<Method> findMethod(URI uri) then change it's access level to be accesssed from TestFactoryTestDescriptor

@gopinath-langote
Copy link
Contributor

@marcphilipp @sbrannen sorry for the late reply.

I did not get time to work on this. Someone else can pick this issue.

I will look for the other one.

Thanks,
Gopinath

@ielatif
Copy link
Contributor

ielatif commented May 22, 2019

@gopinath-langote I am on it. Thanks

@marcphilipp
Copy link
Member

@gopinath-langote No worries, thanks for letting us know!

magictractor pushed a commit to magictractor/zillions that referenced this issue May 22, 2019
URIs for test methods are now as described in pending JUnit issue for
supporting MethodSource as custom test source in dynamic tests. This
should be verified manually once the JUnit issue has been resolved.

See junit-team/junit5#1850.
ielatif added a commit to ielatif/junit5 that referenced this issue May 23, 2019
… to a MethodSource

Introduce support for converting from a URI of the form method:<FQMN> to a MethodSource, where FQMN is the fully qualified method name. See the Javadoc for DiscoverySelectors.selectMethod(String) for the supported formats for a FQMN. Closes junit-teamgh-1850
ielatif added a commit to ielatif/junit5 that referenced this issue May 24, 2019
… to a MethodSource

Introduce support for converting from a URI of the form method:<FQMN> to a MethodSource, where FQMN is the fully qualified method name. See the Javadoc for DiscoverySelectors.selectMethod(String) for the supported formats for a FQMN. Closes junit-teamgh-1850
@sbrannen sbrannen modified the milestones: 5.6 Backlog, 5.5 RC1 May 24, 2019
@sbrannen
Copy link
Member

Tentatively slated for 5.5 RC1 since PR #1895 has been submitted.

@ielatif
Copy link
Contributor

ielatif commented May 24, 2019

@sbrannen @marcphilipp we have to update issue Deliverables to reflect the changes.

@sbrannen
Copy link
Member

@sbrannen @marcphilipp we have to update issue Deliverables to reflect the changes.

Done 👍

marcphilipp added a commit to ielatif/junit5 that referenced this issue May 28, 2019
marcphilipp added a commit that referenced this issue May 28, 2019
magictractor pushed a commit to magictractor/zillions that referenced this issue Jun 18, 2019
JUnit 5.5.0-RC1 adds support for MethodSource URIs.
See junit-team/junit5#1850
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants