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

Sort tree nodes by name or duration #1179

Merged
merged 2 commits into from
Feb 9, 2025
Merged

Sort tree nodes by name or duration #1179

merged 2 commits into from
Feb 9, 2025

Conversation

rowo360
Copy link
Contributor

@rowo360 rowo360 commented Feb 8, 2025

This PR solves #1149 by adding a context menu that allows the tree to be sorted by duration.

Here's a brief overview of the functionality:

  • the tree nodes can be either be sorted by name or duration
  • it support ascending or descending order
  • if duration sorting is selected, the 'Show duration' option is automatically enabled
  • if duration sorting is selected, but no test durations are available at all, the testnodes are sorted by name
  • if duration sorting is selected, but test durations are only available partly (subset of tests was executed), the name sorting is applied in general, but the subtree with duration results is sorted by duration.
  • the sorting options are not stored in the settings or VisualState file
  • however if a new project is loaded, the current active sorting options are applied to the newly loaded tree.
  • The focus of this issue is the sorting in the NUnit tree display format. However the sorting works also with the Fixture and Test list display format.

@rowo360 rowo360 self-assigned this Feb 8, 2025
@rowo360
Copy link
Contributor Author

rowo360 commented Feb 8, 2025

The idea of solving this problem via a context menu was discussed already previously.
Another solution idea is introducing a duration filter.
For example: filtering by slow, medium or fast tests.

That idea can also be implemented well from a technical point of view. However it requires that the boundaries for slow, medium and fast tests must be adjustable by the user somehow. Because we do not expect to be able to define a value that fits all users equally well. Moreover there are concerns that users are really interested in showing only the fast or medium running tests at all.
Instead, the most important use case will be to quickly identify the long-running tests. And this can be easily achieved with the solution via the context menu.

@rowo360
Copy link
Contributor Author

rowo360 commented Feb 8, 2025

The Windows Forms TreeView class already supports sorting functionality. It only requires a IComparer implementation for the comparision of tree nodes. Therefore I implemented 2 IComparer classes:

  • Comparing the Name of TestNode
  • Comparing the Duration

The tree node sorting is applied whenever the user selects one item in the context menu. But it's also invoked at the end of a test run, when the option 'Show Test duration' is active.

@rowo360
Copy link
Contributor Author

rowo360 commented Feb 8, 2025

One additional comment independent from this issue:
I noticed that the sorting is not as expected if you hide a namespace. Here's a screenshot:

When hiding the namespaces the tree nodes remain in the identical order, resulting that there's no alphabetical order anymore.

With this PR the tree nodes are sorted alphabetical now also when hiding the namespaces.

@rowo360 rowo360 merged commit 06b5b40 into main Feb 9, 2025
2 checks passed
@rowo360 rowo360 deleted the issue-1149 branch February 9, 2025 07:17
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