testng icon indicating copy to clipboard operation
testng copied to clipboard

Allow users to access factory method params info

Open krmahadevan opened this issue 1 year ago • 4 comments

Closes #3111

TestNG now exposes the IParameterInfo interface Via which you can extract the following details Pertaining to a factory powered test.

  • the index - which would match with what was Specified in the “indices” attribute of the “Factory” Annotation. If nothing was specified, then this Would be equal to a running count on the total instances.

  • current index - which represents a running count On the total instances.

  • The parameters of the factory method

  • The instance that was produced.

Fixes #3111 .

Did you remember to?

  • [X] Add test case(s)
  • [X] Update CHANGES.txt
  • [X] Auto applied styling via ./gradlew autostyleApply

We encourage pull requests that:

  • Add new features to TestNG (or)
  • Fix bugs in TestNG

If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the TestNG-dev before you spend time working on it.

Note: For more information on contribution guidelines please make sure you refer our Contributing section for detailed set of steps.

Summary by CodeRabbit

  • New Features
    • Introduced interfaces for handling factory methods and their parameters in tests, enhancing parameter retrieval and method sorting capabilities.
  • Refactor
    • Updated method calls and logic related to factory methods to utilize new interfaces, improving code efficiency and maintainability.
  • Deprecations
    • Deprecated certain functionalities in favor of newer, more efficient methods.
  • Bug Fixes
    • Fixed parameter retrieval logic in test configuration, ensuring accurate handling of test parameters.

krmahadevan avatar Apr 23 '24 05:04 krmahadevan

Walkthrough

The updates across various TestNG files primarily enhance the handling of factory methods and their parameters using the Optional class, deprecate old functionalities, and streamline instance management. This includes introducing new interfaces and updating existing ones to improve code clarity and maintainability.

Changes

File Path Change Summary
testng-core-api/src/main/java/org/testng/IFactoryMethod.java Introduced IFactoryMethod interface with getParameters() method returning parameters wrapped in Optional.
testng-core-api/src/main/java/org/testng/ITestClassInstance.java Introduced ITestClassInstance interface for retrieving factory method parameters.
testng-core-api/src/main/java/org/testng/ITestNGMethod.java Added getFactoryMethod() method returning an Optional<IFactoryMethod>.
testng-core-api/src/main/java/org/testng/internal/IParameterInfo.java Deprecated functionality and extended compatibility with new interfaces.
testng-core/src/main/java/org/testng/DependencyMap.java,
testng-core/src/main/java/org/testng/internal/BaseTestMethod.java,
testng-core/src/main/java/org/testng/internal/MethodSorting.java,
testng-core/src/test/java/test/configuration/issue2426/MyMethodListener.java,
testng-runner-api/src/main/java/org/testng/internal/TestResult.java
Refactored to utilize new interfaces and methods, enhancing parameter handling and instance management.

Assessment against linked issues

Objective Addressed Explanation
Replacement API for IClass.getInstanceHashCodes() and IClass.getInstances(boolean) (#3111) No direct replacement API for these methods has been introduced or modified in the changes listed.

Possibly related issues

  • Issue #3082: The changes to instance and parameter handling might affect the instance retrieval issues mentioned, particularly in listener implementations. More investigation is needed to confirm.
  • Issue #2679: Streamlining instance and factory method handling could indirectly contribute to the clarity of object factory usage, although the specific objectives of this issue are not directly addressed.

🐇✨ A hop through the code, with care and glee, Refactoring done, improvements we see! Optional wraps, parameters align, TestNG's new charm, in code does shine! 🌟📜🐾


Recent Review Details

Configuration used: CodeRabbit UI Review profile: CHILL

Commits Files that changed from the base of the PR and between 43af2cf3232a871c22f48f3c83f1e1fc982f2ebf and f11c4fc56158ca0807b6c4278fc69d36b676c962.
Files selected for processing (20)
  • CHANGES.txt (1 hunks)
  • testng-core-api/src/main/java/org/testng/IFactoryMethod.java (1 hunks)
  • testng-core-api/src/main/java/org/testng/ITestClassInstance.java (1 hunks)
  • testng-core-api/src/main/java/org/testng/ITestNGMethod.java (2 hunks)
  • testng-core-api/src/main/java/org/testng/internal/IParameterInfo.java (1 hunks)
  • testng-core/src/main/java/org/testng/DependencyMap.java (2 hunks)
  • testng-core/src/main/java/org/testng/TestClass.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/BaseTestMethod.java (5 hunks)
  • testng-core/src/main/java/org/testng/internal/ClassImpl.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/FactoryMethod.java (4 hunks)
  • testng-core/src/main/java/org/testng/internal/MethodSorting.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/ParameterInfo.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/TestNGClassFinder.java (3 hunks)
  • testng-core/src/test/java/test/configuration/issue2426/MyMethodListener.java (2 hunks)
  • testng-core/src/test/java/test/factory/FactoryIntegrationTest.java (4 hunks)
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestSample.java (1 hunks)
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithIndicesSample.java (1 hunks)
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderSample.java (1 hunks)
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample.java (1 hunks)
  • testng-runner-api/src/main/java/org/testng/internal/TestResult.java (2 hunks)
Files skipped from review as they are similar to previous changes (19)
  • CHANGES.txt
  • testng-core-api/src/main/java/org/testng/IFactoryMethod.java
  • testng-core-api/src/main/java/org/testng/ITestClassInstance.java
  • testng-core-api/src/main/java/org/testng/ITestNGMethod.java
  • testng-core-api/src/main/java/org/testng/internal/IParameterInfo.java
  • testng-core/src/main/java/org/testng/DependencyMap.java
  • testng-core/src/main/java/org/testng/TestClass.java
  • testng-core/src/main/java/org/testng/internal/BaseTestMethod.java
  • testng-core/src/main/java/org/testng/internal/ClassImpl.java
  • testng-core/src/main/java/org/testng/internal/FactoryMethod.java
  • testng-core/src/main/java/org/testng/internal/MethodSorting.java
  • testng-core/src/main/java/org/testng/internal/ParameterInfo.java
  • testng-core/src/main/java/org/testng/internal/TestNGClassFinder.java
  • testng-core/src/test/java/test/configuration/issue2426/MyMethodListener.java
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestSample.java
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithIndicesSample.java
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderSample.java
  • testng-core/src/test/java/test/factory/issue3111/SimpleFactoryPoweredTestWithoutDataProviderWithIndicesSample.java
  • testng-runner-api/src/main/java/org/testng/internal/TestResult.java
Additional comments not posted (3)
testng-core/src/test/java/test/factory/FactoryIntegrationTest.java (3)

36-38: The updated error message correctly reflects the new requirements for factory methods. Good job on maintaining clarity in the test expectations.


62-63: The updated error message accurately reflects the new type requirements for factory methods. This change enhances the clarity and correctness of the test.


103-110: The data provider is correctly set up to supply the necessary test data for the ensureCurrentIndexWorksForFactoryPoweredTests method. Well done on maintaining clarity and correctness in the test setup.


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.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Apr 23 '24 05:04 coderabbitai[bot]

ping @juherr - Please let me know if there are any other comments that need to be addressed or if this can be merged

krmahadevan avatar Apr 29 '24 12:04 krmahadevan

I'm working on it. I'm fighting against the issues of the legacy model.

juherr avatar Apr 29 '24 12:04 juherr

I'm working on it. I'm fighting against the issues of the legacy model.

May the force be with you :) Will wait to hear back from you

krmahadevan avatar Apr 29 '24 13:04 krmahadevan