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 FilePosition in discovery selectors #2146

Closed
mpkorstanje opened this issue Jan 12, 2020 · 8 comments · Fixed by #2253
Closed

Support FilePosition in discovery selectors #2146

mpkorstanje opened this issue Jan 12, 2020 · 8 comments · Fixed by #2253

Comments

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Jan 12, 2020

Currently there is no good way to discover and execute a single test when using a file based test system like Cucumber. So I would like to request support for a file position in UriSelector, FileSelector and ClasspathResourceSelector.

Deliverables

Support for a file position when using:

  • URI selectors
  • File selectors
  • Classpath resource selectors

Motivation

Cucumber executes feature files written in Gherkin. A feature file consists of multiple scenarios organized in a hierarchical structure. A project may contain multiple feature files, typically organized in some directory structure.

For example:

|- src/main/java/com/example
| |- App.java
|- src/test/java/com/example
| |- StepDefinitions.java
|- src/test/resource/com/example/
| |- single.feature
| |- rule.feature
| |- outline.feature

Contents of outline.feature:

Feature: A feature with scenario outlines

  Scenario: A scenario
    Given a scenario
    When it is executed
    Then is only runs once

  Scenario Outline: A scenario outline
    Given a scenario outline
    When it is executed
    Then <example> is used

    Examples: With some text
      | example |
      | A       |
      | B       |

    Examples: With some other text
      | example |
      | C       |
      | D       |

outline.feature contains 5 tests in a hierarchy:

A feature with scenario outlines
|- A scenario
|- A scenario outline
| |- With some text
| | |- Example #1
| | |- Example #2
| |- With some other text
| | |- Example #1
| | |- Example #2

Now suppose I would like select both tests (Example #1, Example #2) nested under the example With some text on line 17.

Currently JUnit discovery selectors (ClasspathRootSelector, ClasspathResourceSelector, PackageSelector, FileSelector, DirectorySelector) only allow me to discover all tests in a single directory or file.

The UniqueIdSelector could be used to select the With some text container but requires reproducing the unique id which is rather complicated and quite possibly an implementation detail that should not be relied upon.

Cucumbers currentTestEngine implementation currently allows for a line query parameter to be added in when parsing using the UriSelector. For example:

  • classpath:/com/example/outline.feature?line=17
  • file:/home/mpkorstanje/projects/cucumber/src/test/resources/com/example/outline.feature?line=17

Since this is not formalized I suspect other test engines that consume the UriSelector may crash on the query parameter and so I would like something safer.

For IDEs being able to use a FileSelector with a file position would also simplify the complexity of providing support for file based test engines. Naively allowing the user to select any line in a file and execute the discovered tests for that line would provide for a minimal implementation without knowing any details about the underlying implementation of the test engine.

The same reasoning applies to ClasspathResourceSelector.

@sbrannen
Copy link
Member

Good points!

Note that we actually already have support for FilePosition in FileSource, ClassSource, and ClasspathResourceSource.

See FilePosition.fromQuery(String) for the supported syntax.

Thus, adding the support proposed in this issue would align our FilePosition support in sources and selectors, making that support symmetrical which it arguably should have already been.

I am therefore in favor of adding this support to selectors.

@junit-team/junit-lambda, thoughts?

@sbrannen
Copy link
Member

Tentatively slated for 5.7 M1 for team discussion

@sbrannen sbrannen changed the title Support a file position in test selectors Support FilePosition in test selectors Jan 13, 2020
@sbrannen sbrannen changed the title Support FilePosition in test selectors Support FilePosition in discovery selectors Jan 13, 2020
@marcphilipp
Copy link
Member

Team decision: Add FilePosition as an optional property of FileSelector and ClasspathResourceSelector.

Challenge: FilePosition is in the ..support.descriptor package which cannot be accessed from the ..discovery package.

@timtebeek
Copy link
Contributor

Hi! First time contributor here; I've started out with adding FilePosition as optional argument to FileSelector and ClasspathResourceSelector here: master...timtebeek:master

Not sure if this was as intended; and it's likely nowhere near done to resolve this issue, but I'd like to get some feedback on what should be the next logical steps. To start with:

  • The challenge outline above has me slightly confused as to what would (not) be required to resolve the issue. Can anyone expand on that a bit?
  • While @mpkorstanje mentioned he would also like to see file position added to UriSelector there's no mention of it in the team decision; Is that out of scope for this feature?
  • Would I need to add methods with FilePosition argument to org.junit.platform.engine.discovery.DiscoverySelectors ?

Any further guidance would be much appreciated; I had thought to open a pull request only if it seems feasible I'll be able to finish the implementation.

@marcphilipp
Copy link
Member

@timtebeek Sorry for the delay in response, I hope you're still interested. 🙂

The challenge outline above has me slightly confused as to what would (not) be required to resolve the issue. Can anyone expand on that a bit?

We wouldn't like to duplicate the FilePosition class but cannot reference it from the selectors without introducing a package cycle. Thus, we'll probably have to copy it to the new location, inherit from it in the old location, and deprecate it there. Unless anyone has any better ideas?

* While @mpkorstanje mentioned he would also like to see file position added to `UriSelector` there's no mention of it in the team decision; Is that out of scope for this feature?

UriSource doesn't have it since you can simply add it as query parameters. Thus, we decided it was unnecessary to add to UriSelector. So, yes, it's out of scope for this issue.

Would I need to add methods with FilePosition argument to org.junit.platform.engine.discovery.DiscoverySelectors ?

Yes, since all new constructors should be package-private.

@timtebeek
Copy link
Contributor

@timtebeek Sorry for the delay in response, I hope you're still interested.

No problem at all; happy to help out.

The challenge outline above has me slightly confused as to what would (not) be required to resolve the issue. Can anyone expand on that a bit?

We wouldn't like to duplicate the FilePosition class but cannot reference it from the selectors without introducing a package cycle. Thus, we'll probably have to copy it to the new location, inherit from it in the old location, and deprecate it there. Unless anyone has any better ideas?

Any suggestions as to where to place it? It's my first time contributing here, so not too familiar with where it should go.

* While @mpkorstanje mentioned he would also like to see file position added to `UriSelector` there's no mention of it in the team decision; Is that out of scope for this feature?

UriSource doesn't have it since you can simply add it as query parameters. Thus, we decided it was unnecessary to add to UriSelector. So, yes, it's out of scope for this issue.

Would I need to add methods with FilePosition argument to org.junit.platform.engine.discovery.DiscoverySelectors ?

Yes, since all new constructors should be package-private.

Perfect; will do!

@marcphilipp
Copy link
Member

Any suggestions as to where to place it? It's my first time contributing here, so not too familiar with where it should go.

I'm leaning towards adding it to org.junit.platform.engine.discovery so let's start with that.

@timtebeek
Copy link
Contributor

@marcphilipp I've applied your suggestions and opened up #2253 for further discussion. :)

@marcphilipp marcphilipp modified the milestones: 5.7 M1, 5.7 M2 Apr 17, 2020
juliette-derancourt pushed a commit that referenced this issue May 22, 2020
This commit adds the possibility to select files and classpath resources with a given `FilePosition` (line and/or column number).

Resolves #2146.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 13, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 13, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 13, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 13, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 13, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 13, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 13, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 14, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 14, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
mpkorstanje added a commit to cucumber/cucumber-jvm that referenced this issue Sep 14, 2020
There was no good way to discover and execute a single test when using a file
based test system like Cucumber. Recently JUnit added support for file position
in the `FileSelector` and `ClasspathResourceSelector`.

See: junit-team/junit5#2146

This implements a filter that prunes all scenarios that do not match the
`FilePosition` from the discovery selector. This feature itself is not new. It
was already implemented for the `UriSelector`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants