Skip to content

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented Sep 17, 2025

🤔 What's changed?

Adds

  • findAllTestCaseStartedInCanonicalOrder
  • findAllTestCaseFinishedInCanonicalOrder

⚡️ What's your motivation?

To provide consistent results while executing in parallel, the Cucumber JSON, Teamcity, Pretty, and Rerun formatters all prints results in canonical order. This results in quite some duplication.

The canonical order is for the TestCase{Started,Finished} event is the order of their pickles they execute. Ordered by lexical URI and then from top to bottom in the feature file.

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ Anything particular you want feedback on?

I'm not happy with the InCanonicalOrder suffix yet. Ideally the method would have a OrderBy suffix, taking a function that finds a relationship, and a comparator to order on that relationship.

I.e.

    public <T> List<TestCaseStarted> findAllTestCaseStartedOrderBy(BiFunction<Query, TestCaseStarted, Optional<T>> findOrderBy, Comparator<T> order) {
        return findAllTestCaseStarted().stream()
                .map(testCaseStarted -> findOrderBy.apply(this, testCaseStarted)
                        .map(orderBy -> new OrderableMessage<>(testCaseStarted, orderBy))
                        .orElseGet(() -> new OrderableMessage<>(testCaseStarted)))
                .sorted(Comparator.comparing(OrderableMessage::getOrderBy, order))
                .map(OrderableMessage::getMessage)
                .collect(toList());
    }

Then this can be used as:

query.findAllTestCaseStartedOrderBy(
                        Query::findPickleBy,
                        Comparator.nullsFirst(new PickleComparator())
                )

But this requires cucumber/messages#308 to be implemented so it is possible to make PickleComparator nicely without reaching back into query (slow).

📋 Checklist:

  • Consider awaiting Add location to pickle messages#308 to reduce implementation complexity.
  • Document what canonical order is
  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

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

Successfully merging this pull request may close these issues.

1 participant