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

Minor refactoring around RunOrder enum #3106

Merged
merged 1 commit into from
Mar 31, 2024

Conversation

krmahadevan
Copy link
Member

@krmahadevan krmahadevan commented Mar 30, 2024

Renamed and re-organised some internal classes

The run order based on instances was using
Hash codes to determine execution order.
Now that we have Unique identity aware test class
object containers, we should be first trying to
use that and if it’s not available only then fall
Back to using object hash codes
(This is for instance aware comparators)

Summary by CodeRabbit

  • New Features
    • Introduced a new method sorting functionality across the framework for more flexible and configurable test method ordering.
    • Added a new interface to assist in creating comparators for test method execution order.
    • Implemented an enum to provide sorting options based on method names, priorities, class names, factory method parameters, and instance identity.
  • Refactor
    • Modified method ordering logic to remove default value assignment for system properties.
    • Updated various components to use the new method sorting mechanism, enhancing the way methods are sorted based on dependencies and other criteria.
  • Tests
    • Adjusted base test configurations to align with the new method sorting approach.

Renamed and re-organised some internal classes

The run order based on instances was using 
Hash codes to determine execution order.
Now that we have Unique identity aware test class
object containers, we should be first trying to 
use that and if it’s not available only then fall
Back to using object hash codes 
(This is for instance aware comparators)
Copy link

coderabbitai bot commented Mar 30, 2024

Walkthrough

The recent updates to TestNG focus on refining method ordering and sorting mechanisms. The introduction of MethodSorting replaces Systematiser use across several components, enhancing the method comparison logic. Additionally, adjustments in handling properties and method identity checks signify a move towards more explicit and reliable test execution order, addressing past ambiguities.

Changes

File Path Change Summary
.../internal/RuntimeBehavior.java Removed default value for "testng.order" in orderMethodsBasedOn().
.../TestNG.java, .../TestRunner.java, .../reporters/FailedReporter.java Replaced Systematiser.getComparator() with MethodSorting.basedOn().
.../internal/IInstanceIdentity.java Added isIdentityAware static method.
.../internal/IOrderMethods.java New interface for creating method execution order Comparator.
.../internal/MethodSorting.java New enum for method sorting functionality.
.../test/java/test/BaseTest.java Replaced Systematiser with MethodSorting for method sorting.

Possibly related issues

Poem

In the realm of code where tests align,
A rabbit hopped, making everything fine.
🐇 With a flip and a hop, sorting methods anew,
Fixing the old, introducing what's true.
"To order, to sort," it whispered with glee,
Ensuring that TestNG as smooth as can be.
🌟 In the moonlight, its work gleams so bright,
A testament to tests that now run just right.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e5218ab and 66f056e.
Files selected for processing (8)
  • testng-core-api/src/main/java/org/testng/internal/RuntimeBehavior.java (1 hunks)
  • testng-core/src/main/java/org/testng/TestNG.java (2 hunks)
  • testng-core/src/main/java/org/testng/TestRunner.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/IInstanceIdentity.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/IOrderMethods.java (1 hunks)
  • testng-core/src/main/java/org/testng/internal/MethodSorting.java (1 hunks)
  • testng-core/src/main/java/org/testng/reporters/FailedReporter.java (2 hunks)
  • testng-core/src/test/java/test/BaseTest.java (3 hunks)
Additional Context Used
Additional comments not posted (12)
testng-core/src/main/java/org/testng/internal/IOrderMethods.java (1)

1-15: The IOrderMethods interface is well-defined and documented, providing a clear contract for producing a Comparator<ITestNGMethod>. This approach enhances modularity and flexibility in defining method order logic.

testng-core/src/main/java/org/testng/internal/IInstanceIdentity.java (2)

3-4: The imports for Arrays and Objects are correctly added and necessary for the implementation of the isIdentityAware method.


22-29: The isIdentityAware method is efficiently implemented using Java streams and lambda expressions. It correctly handles null inputs and checks if all passed objects are instances of IInstanceIdentity, adhering to best practices.

testng-core/src/main/java/org/testng/internal/MethodSorting.java (3)

1-85: The MethodSorting enum is well-designed, encapsulating different sorting strategies for test methods in a type-safe manner. It provides a flexible and extensible way to define and apply sorting logic.


31-47: Consider refining the comparison logic in the INSTANCES strategy to ensure deterministic behavior. The use of Object::toString might introduce non-deterministic sorting due to varying toString implementations. Replacing or removing this part of the comparison chain could enhance consistency.


73-83: The basedOn and parse methods are correctly implemented, providing a flexible way to configure the sorting behavior based on system properties. This approach enhances the adaptability of the sorting logic.

testng-core-api/src/main/java/org/testng/internal/RuntimeBehavior.java (1)

96-96: The modification to no longer provide a default value for the "testng.order" property enhances configurability for method sorting. Consider documenting this change or including it in release notes to inform users and guide them on explicitly configuring the sorting behavior if necessary.

testng-core/src/test/java/test/BaseTest.java (2)

171-171: The replacement of Systematiser with MethodSorting in the run method correctly aligns with the new method sorting logic, enhancing flexibility and configurability for test method ordering.


349-349: The usage of MethodSorting in the newTestRunner method of InternalTestRunnerFactory correctly implements the new sorting logic, ensuring that test methods are sorted according to the configured strategy.

testng-core/src/main/java/org/testng/reporters/FailedReporter.java (1)

114-114: The replacement of Systematiser.getComparator() with MethodSorting.basedOn() in the generateXmlTest method correctly aligns with the new method sorting logic, enhancing the accuracy and flexibility of method ordering in the context of generating test reports for failed and skipped tests.

testng-core/src/main/java/org/testng/TestRunner.java (1)

220-220: The replacement of Systematiser.getComparator() with MethodSorting.basedOn() aligns with the PR's objective to improve method execution ordering logic by leveraging unique identity-aware test class object containers. Ensure that MethodSorting.basedOn() is implemented to prioritize unique identities over hash codes and integrates well with the existing system without introducing regressions.

testng-core/src/main/java/org/testng/TestNG.java (1)

36-36: The import of MethodSorting is correctly added, and its usage in MethodSorting.basedOn() replaces Systematiser.getComparator() as intended.

Ensure the implementation of MethodSorting.basedOn() aligns with the new method ordering logic.

@@ -1362,7 +1362,7 @@ private SuiteRunner createSuiteRunner(XmlSuite xmlSuite) {
container,
m_classListeners.values(),
holder,
Systematiser.getComparator());
MethodSorting.basedOn());
Copy link

Choose a reason for hiding this comment

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

Consider refactoring the createSuiteRunner method to improve readability and maintainability. Breaking it into smaller, more focused methods could enhance the code structure and make it easier to understand and modify in the future.

@krmahadevan krmahadevan merged commit 2e5d8bf into testng-team:master Mar 31, 2024
7 of 9 checks passed
@krmahadevan krmahadevan deleted the minor_refactoring branch March 31, 2024 02:40
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.

2 participants