-
Notifications
You must be signed in to change notification settings - Fork 542
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
Enabling Surefire to run test classes and test methods in any order specified by a new runOrder #348
base: master
Are you sure you want to change the base?
Conversation
…pecified by a runOrder
Hi @winglam I checked your commit. |
Hello @Tibor17 Thanks for following up on these changes. I'm a bit busy this week but I will plan on updating these changes by next week. Currently, my changes seem to use |
The
The problem is that we do not work with methods. Only classes. So all you have to do is to serialize run order (enum + data), see The system property and TestListResolver parts can be avoided. |
It would help you and us if you have followed these steps, in separate commits, and each step would have unit tests:
|
Of course the documentation should say that |
Maybe a hint, try to run a basic project in debug mode |
@Tibor17 Thanks a lot for the detailed information, especially the list of steps. I still have these changes on my list of todos and hope to get to them soon. Hopefully by the time I have something ready PR 440 would be merged by then. I'll reach out again once I have made some progress on some of the steps. |
How are you @winglam? |
I'll try to help move this PR forward. I'll start by trying to bring this branch uptodate with master. What's the easiest way to collaborate? I could send a pr to the |
@aslakhellesoy |
@Tibor17 and @aslakhellesoy I would be happy to participate in the discussion for this feature. Unfortunately, I would not have time to implement the five-step process that Tibor laid out by myself until this May. @aslakhellesoy If you are able to implement the five steps before then, please feel free to do so. I would be happy to look over a PR and work with you to get this feature out the door. Please let me know if this option interests you and how may I help. |
Hi @winglam - I have created a JIRA issue related to this: https://issues.apache.org/jira/browse/SUREFIRE-2041, with a related PR: #495 In that JIRA issue I have outlined why I don't think ordering test methods is possible (only classes). I'd be interested in your thoughts about this. |
@winglam |
@aslakhellesoy as the very first message in this PR explains already, the capability for Surefire to order test methods is already implemented -- albeit implemented in a way that Tibor would prefer that we change to merge the feature into Surefire. Mainly we just need to follow the steps Tibor outlined so that Surefire can order not just classes but also methods. Happy to comment on the work or test it out, but I won't have time to implement it myself for the next few weeks. |
@winglam your implementation of test method ordering can order tests within the same class, but it cannot order them globally. For example, if you specify
This is because Surefire runs one test class at a time. Supporting a global ordering of test methods would require such a significant refactoring that I'm not sure it's realistic to attempt it. The JUnit 5 team has said they won't support it: junit-team/junit5#2857 As I have described in SUREFIRE-2041 I think the best we can do is an explicit class ordering. I have implemented class ordering in #495, inspired from this PR but with a different implementation. I'm waiting for @Tibor17 to approve the running of the GitHub Action in that PR, and also to review the code. |
@aslakhellesoy Thanks for the clarification. I was aware from the https://issues.apache.org/jira/browse/SUREFIRE-2041 issue that you wanted a global test method ordering feature that supports the interleaving of test methods across test classes and I agree that it may not be realistic to attempt. More importantly, I'm not sure how one would implement such a feature. Namely, how should one handle class setup and teardown methods (e.g., @BeforeClass from JUnit) for an order such as testing.Y#a,testing.X#c,testing.Y#b? Should one run testing.Y#beforeClass,testing.Y#a,testing.X#beforeClass,testing.X#c,testing.Y#beforeClass,testing.Y#b? What if running testing.Y#beforeClass twice without running testing.Y#afterClass causes a failure? We could then run testing.Y#afterClass after testing.Y#a and before testing.X#beforeClass but then that can add substantial time cost to running tests and still cause unexpected failures if these class setup and teardown methods are not expected to run twice in one JVM. Not supporting a global test method ordering feature is a purposeful design feature when I did my implementation of test method ordering. For the same reason we may not want to support the feature of interleaving test classes across different modules (e.g., module1.testing.Y,module2.testing.X,module1.testing.Z), I'm not sure whether a global test method ordering feature should be supported or not based on the way modules and test classes are defined and commonly used. I believe there is still much value to support test method ordering within classes (and also the ordering of test classes) and the changes I have in this PR accomplishes both test class ordering and test method ordering, just not the interleaving of test methods across classes and in the way that Tibor suggests us to do so for this feature. |
@winglam are you by any chance working on a Test Case Prioritization engine? I am :-) I went on a little twitter rant about it yesterday. If JUnit implemented global test method ordering, I think It's still possible to do TCP with class ordering. The APFD would be lower than with a method ordering, but still better than no ordering! FWIW, Cucumber-Ruby and Cucumber-JS do support global scenario ordering - they can run scenarios in any order even if they are in different files. |
I am not actively working on a test prioritization engine at the moment but have some work on it in the past, e.g., https://cs.gmu.edu/~winglam/publications/2020/LamETAL20ISSTA.pdf I agree with your Twitter post that we should ideally be able to run them in any order (even orders that interleave) but as you pointed out, such a feature should probably first come from JUnit before it gets to Surefire. I also agree that it is still possible to do TCP with class ordering, but why stop at class ordering? Why not have your TCP be done at class + non-interleaving method ordering? As we've discussed, global test ordering or interleaving method ordering is going to require substantial efforts to accomplish, but class + non-interleaving method ordering is already supported in this PR and just requires one to improve this PR according to the suggestions Tibor provided. Thanks for the heads up about Cucumber. I was not aware that the framework supported global test ordering. Do they run @BeforeClass (or their version of it) once before the first test even if methods from different classes are interleaved? |
@Tibor17 I will have some time for this change now and plan to complete it in the next few weeks. Just want to confirm: are you still interested in this change and do you still want me to follow the steps you laid out earlier (#348 (comment))? |
The changes in this pull request enable Surefire to run test classes and test methods in any order specified by a newly added <runOrder> (testorder). Namely, the changes include
The newly added testorder <runOrder> is supported for all JUnit 3 and JUnit 4 tests. I will plan on supporting JUnit 5 and testng tests after these changes are accepted.
Simple (no regex) example using Dubbo:
Output from Maven should say that the test class
DubboLazyConnectTest
ran beforeDubboProtocolTest
The file
DubboLazyConnectTest.xml
(dubbo-rpc/dubbo-rpc-dubbo/target/surefire-reports/TEST-org.apache.dubbo.rpc.protocol.dubbo.DubboLazyConnectTest.xml
) should sayRegex example using Dubbo:
Output from Maven should say
The file
DubboProtocolTest.xml
(dubbo-rpc/dubbo-rpc-dubbo/target/surefire-reports/TEST-org.apache.dubbo.rpc.protocol.dubbo.DubboProtocolTest.xml
) should sayInclude/Exclude example using Dubbo:
Output from Maven should say
Tests run: 3 … in org.apache.dubbo.rpc.protocol.dubbo.DubboLazyConnectTest
The file
DubboLazyConnectTest.xml
(dubbo-rpc/dubbo-rpc-dubbo/target/surefire-reports/TEST-org.apache.dubbo.rpc.protocol.dubbo.DubboLazyConnectTest.xml
) should say