Skip to content

Introduce support for ordering test classes#2488

Closed
ledoyen wants to merge 1 commit intojunit-team:mainfrom
ledoyen:issues/1948-class-ordering
Closed

Introduce support for ordering test classes#2488
ledoyen wants to merge 1 commit intojunit-team:mainfrom
ledoyen:issues/1948-class-ordering

Conversation

@ledoyen
Copy link
Copy Markdown
Contributor

@ledoyen ledoyen commented Dec 8, 2020

Issue: #1948

Overview

Introduce support for class ordering through the addition of a new configuration parameter:

  • junit.jupiter.testclass.order.default accepting a fully-qualified class-name implementing the newly introduced org.junit.jupiter.api.ClassOrderer interface

I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

@ledoyen ledoyen force-pushed the issues/1948-class-ordering branch 9 times, most recently from 2fd7e1a to 5dcc10d Compare December 11, 2020 23:36
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 11, 2020

Codecov Report

Merging #2488 (82cbc6d) into main (e08ab9e) will decrease coverage by 0.02%.
The diff coverage is 87.70%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #2488      +/-   ##
============================================
- Coverage     90.56%   90.53%   -0.03%     
- Complexity     4683     4708      +25     
============================================
  Files           407      413       +6     
  Lines         11568    11646      +78     
  Branches        923      924       +1     
============================================
+ Hits          10476    10544      +68     
- Misses          814      824      +10     
  Partials        278      278              
Impacted Files Coverage Δ Complexity Δ
...main/java/org/junit/jupiter/api/MethodOrderer.java 100.00% <ø> (ø) 1.00 <0.00> (ø)
.../discovery/AbstractAnnotatedElementDescriptor.java 69.23% <69.23%> (ø) 5.00 <5.00> (?)
...jupiter/engine/discovery/ClassOrderingVisitor.java 70.58% <70.58%> (ø) 6.00 <6.00> (?)
...piter/engine/discovery/DefaultClassDescriptor.java 75.00% <75.00%> (ø) 2.00 <2.00> (?)
.../main/java/org/junit/jupiter/api/ClassOrderer.java 84.37% <84.37%> (ø) 0.00 <0.00> (?)
...ter/engine/config/CachingJupiterConfiguration.java 100.00% <100.00%> (ø) 21.00 <2.00> (+2.00)
...ter/engine/config/DefaultJupiterConfiguration.java 100.00% <100.00%> (ø) 14.00 <1.00> (+1.00)
...iter/engine/discovery/AbstractOrderingVisitor.java 100.00% <100.00%> (ø) 12.00 <12.00> (?)
...r/engine/discovery/DefaultClassOrdererContext.java 100.00% <100.00%> (ø) 3.00 <3.00> (?)
...iter/engine/discovery/DefaultMethodDescriptor.java 75.00% <100.00%> (+13.46%) 2.00 <2.00> (-3.00) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e08ab9e...82cbc6d. Read the comment docs.

Copy link
Copy Markdown
Member

@marcphilipp marcphilipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks promising! 👍

Comment thread junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java Outdated
Comment thread junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderingStrategy.java Outdated
Comment thread junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/Constants.java Outdated
@ledoyen ledoyen force-pushed the issues/1948-class-ordering branch 3 times, most recently from 28935c0 to d67ac5e Compare December 19, 2020 18:13
@ledoyen ledoyen force-pushed the issues/1948-class-ordering branch from 38e2595 to baae4bd Compare December 23, 2020 08:37
@ledoyen ledoyen marked this pull request as ready for review December 24, 2020 08:28
@ledoyen ledoyen force-pushed the issues/1948-class-ordering branch from 06c0760 to 4b8c2fc Compare December 24, 2020 08:36
Comment thread junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/Constants.java Outdated
Comment thread junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderingStrategy.java Outdated
Comment thread junit-jupiter-api/src/main/java/org/junit/jupiter/api/Order.java Outdated
Comment thread documentation/src/docs/asciidoc/release-notes/release-notes-5.8.0-M1.adoc Outdated
Comment thread documentation/src/docs/asciidoc/user-guide/writing-tests.adoc Outdated
Comment thread documentation/src/docs/asciidoc/user-guide/writing-tests.adoc Outdated
Comment thread documentation/src/docs/asciidoc/user-guide/writing-tests.adoc Outdated
Comment thread junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java Outdated
@ledoyen ledoyen force-pushed the issues/1948-class-ordering branch from 86c770e to c4a4450 Compare December 28, 2020 12:20
@ledoyen
Copy link
Copy Markdown
Contributor Author

ledoyen commented Dec 28, 2020

Thanks for reviewing this so quickly.

Let me know if that is ok so I can squash commits.

Build on JDK16 & 17 was failing, so I rebased the branch on main, but the issue is still there.
It can be a bug in byte-buddy given similar symptoms with

FYI: Upgrading to mockito 3.6.28 did not fix the issue, but maybe some other library is getting byte-buddy and I am not confortable enough with Gradle to display the test dependency tree, maybe you can see something with the build scan ?

@ledoyen ledoyen force-pushed the issues/1948-class-ordering branch from 489509d to c4a4450 Compare December 28, 2020 13:39
@marcphilipp
Copy link
Copy Markdown
Member

The breakage is most likely unrelated to the changes in this branch. I've upgrade the versions of JDK 16 and 17 in junit-team/build-env@2a4a8a5.

@marcphilipp
Copy link
Copy Markdown
Member

Mockito 3.6.48 also doesn't solve the issue: https://ge.junit.org/s/7nva27dj6tilo/dependencies?dependencies=mockito&expandAll

@marcphilipp
Copy link
Copy Markdown
Member

I reported an issue for Mockito: mockito/mockito#2156

@marcphilipp
Copy link
Copy Markdown
Member

I've reverted back to the working versions of JDK 16 and 17 for now.

@marcphilipp marcphilipp self-requested a review December 28, 2020 21:24
Comment thread documentation/src/docs/asciidoc/release-notes/release-notes-5.8.0-M1.adoc Outdated
Comment thread documentation/src/docs/asciidoc/user-guide/writing-tests.adoc
@ledoyen ledoyen force-pushed the issues/1948-class-ordering branch from c4a4450 to 12e2483 Compare January 3, 2021 19:41
@ledoyen
Copy link
Copy Markdown
Contributor Author

ledoyen commented Jan 3, 2021

Just for my knowledge, do you use some extra tool that is not (yet ?) scripted in CI builds to check on line lengths or is it a manual verification ?

@sbrannen
Copy link
Copy Markdown
Member

sbrannen commented Jan 3, 2021

Just for my knowledge, do you use some extra tool that is not (yet ?) scripted in CI builds to check on line lengths or is it a manual verification ?

We check line lengths manually in documentation (i.e., Asciidoc and Javadoc) and build scripts.

For Java code, we use Spotless.

@sbrannen sbrannen dismissed marcphilipp’s stale review January 25, 2021 10:07

Changes already made

@sbrannen sbrannen linked an issue Jan 28, 2021 that may be closed by this pull request
@sbrannen sbrannen closed this in b3ce7ae Jan 28, 2021
sbrannen added a commit that referenced this pull request Jan 28, 2021
@sbrannen sbrannen self-assigned this Jan 28, 2021
@sbrannen
Copy link
Copy Markdown
Member

This has been merged into main in b3ce7ae and further refined in 49565e9 and 76d4ca3.

Thanks for all of the hard work you put into this new feature.

We really appreciate it! 👍

@sbrannen sbrannen changed the title Introduce support for class ordering Introduce support for ordering test classes Jan 28, 2021
@sbrannen
Copy link
Copy Markdown
Member

@ledoyen, if you have a Twitter account, I'd be grateful if you could share it with me (either here or on Twitter: @sam_brannen).

@ledoyen
Copy link
Copy Markdown
Contributor Author

ledoyen commented Jan 28, 2021

@sbrannen you can find me on Twitter @ledoyen_loic but I am not very active on this platform 😉

@marcphilipp
Copy link
Copy Markdown
Member

Thanks, both of you! 🎉

@sbrannen
Copy link
Copy Markdown
Member

@sbrannen you can find me on Twitter @ledoyen_loic but I am not very active on this platform 😉

Here's why I asked: https://twitter.com/sam_brannen/status/1355131508101705734

@mpkorstanje
Copy link
Copy Markdown
Contributor

@sbrannen this MR is causing the Cross-Version / OpenJDK 17 step to fail for #2416 I think the CI might be leaky.

2021-01-30T14:43:03.5462872Z /__w/junit5/junit5/junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java:78: warning: [missing-explicit-ctor] class ClassName in exported package org.junit.jupiter.api declares no explicit constructors, thereby exposing a default constructor to clients of module org.junit.jupiter.api
2021-01-30T14:43:03.5464651Z 	class ClassName implements ClassOrderer {
2021-01-30T14:43:03.5465108Z 	^
2021-01-30T14:43:03.5467020Z /__w/junit5/junit5/junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java:98: warning: [missing-explicit-ctor] class DisplayName in exported package org.junit.jupiter.api declares no explicit constructors, thereby exposing a default constructor to clients of module org.junit.jupiter.api
2021-01-30T14:43:03.5468749Z 	class DisplayName implements ClassOrderer {
2021-01-30T14:43:03.5469217Z 	^
2021-01-30T14:43:03.5471373Z /__w/junit5/junit5/junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java:128: warning: [missing-explicit-ctor] class OrderAnnotation in exported package org.junit.jupiter.api declares no explicit constructors, thereby exposing a default constructor to clients of module org.junit.jupiter.api
2021-01-30T14:43:03.5473178Z 	class OrderAnnotation implements ClassOrderer {
2021-01-30T14:43:03.5473673Z 	^
2021-01-30T14:43:03.5475541Z /__w/junit5/junit5/junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java:165: warning: [missing-explicit-ctor] class Random in exported package org.junit.jupiter.api declares no explicit constructors, thereby exposing a default constructor to clients of module org.junit.jupiter.api
2021-01-30T14:43:03.5477176Z 	class Random implements ClassOrderer {
2021-01-30T14:43:03.5477605Z 	^
2021-01-30T14:43:03.5478158Z error: warnings found and -Werror specified
2021-01-30T14:43:03.5478589Z 1 error
2021-01-30T14:43:03.5478911Z 4 warnings
2021-01-30T14:43:03.5479135Z 
2021-01-30T14:43:03.5479533Z FAILURE: Build failed with an exception.
2021-01-30T14:43:03.5479877Z 
2021-01-30T14:43:03.5480250Z * What went wrong:
2021-01-30T14:43:03.5480942Z Execution failed for task ':junit-jupiter:compileModule'.

@marcphilipp
Copy link
Copy Markdown
Member

Thanks for reporting, I'm on it.

@marcphilipp
Copy link
Copy Markdown
Member

As it turns out, the compileModule tasks were not tracking their inputs correctly. This led to false cache hits. I've fixed it in 31aaac8 and cherry-picked your commit (dc7cab3) to fix the warnings. Sorry for the inconvenience!

@mpkorstanje
Copy link
Copy Markdown
Contributor

Cheers!

sbrannen added a commit to sbrannen/junit-framework that referenced this pull request Aug 28, 2021
PR junit-team#2488 introduced support for ordering top-level test classes but
did not provide support for ordering @nested test classes.

This commit adds support for ordering @nested test classes as well.

Closes: junit-team#2699
sbrannen added a commit to sbrannen/junit-framework that referenced this pull request Aug 28, 2021
PR junit-team#2488 introduced support for ordering top-level test classes but
did not provide support for ordering @nested test classes.

This commit adds support for ordering @nested test classes as well.

Closes: junit-team#2699
sbrannen added a commit to sbrannen/junit-framework that referenced this pull request Aug 30, 2021
PR junit-team#2488 introduced support for ordering top-level test classes but
did not provide support for ordering @nested test classes.

This commit adds support for ordering @nested test classes.

See: junit-team#2699
sbrannen added a commit that referenced this pull request Aug 30, 2021
PR #2488 introduced support for ordering top-level test classes but
did not provide support for ordering @nested test classes.

This commit adds support for ordering @nested test classes.

See: #2699
runningcode pushed a commit to runningcode/junit5 that referenced this pull request Feb 15, 2023
This commit introduces support for ordering test classes analogous to
the existing support for ordering test methods.

Specifically, this commit introduces a new ClassOrderer API and related
ClassDescriptor and ClassOrdererContext types.

JUnit Jupiter provides the following built-in implementations of the
new ClassOrderer API.

- ClassOrderer.ClassName
- ClassOrderer.DisplayName
- ClassOrderer.OrderAnnotation
- ClassOrderer.Random

The default ClassOrderer implementation can be configured globally via
the configuration parameter: junit.jupiter.testclass.order.default

See the Javadoc and User Guide for details.

Issue: junit-team#1948
Closes: junit-team#2488
runningcode pushed a commit to runningcode/junit5 that referenced this pull request Feb 15, 2023
runningcode pushed a commit to runningcode/junit5 that referenced this pull request Feb 15, 2023
runningcode pushed a commit to runningcode/junit5 that referenced this pull request Feb 15, 2023
PR junit-team#2488 introduced support for ordering top-level test classes but
did not provide support for ordering @nested test classes.

This commit adds support for ordering @nested test classes.

See: junit-team#2699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce @TestClassOrder for ordering test classes in JUnit Jupiter

4 participants