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

Allow data providers to be non cacheable #3076

Merged
merged 1 commit into from Feb 26, 2024

Conversation

krmahadevan
Copy link
Member

@krmahadevan krmahadevan commented Feb 25, 2024

Closes #3041

We can now configure TestNG to enable/disable
caching of test data produced by a data provider
when TestNG is retrying a failed test method using the attribute “cacheDataForTestRetries” on the
@dataProvider” annotation.

Below is a sample, which forces TestNG to re-invoke the data provider when a test method fails and it needs to be retried.

@DataProvider(name = "dp", cacheDataForTestRetries = false)
public Object[][] getData() {
  return new Object[][] {{1}, {2}};
}

Fixes #3041

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt
  • 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
    • Users can now define the order for TestNG listeners.
  • Bug Fixes
    • Aligned TestNG 7.x DataProvider behavior with TestNG 6.x for test retries.
    • Restored the ability to dynamically adjust the number of TestNG threads.
    • Moved Ant support to its own repository for better management.
    • Introduced caching control for data used in test retries, improving efficiency in test execution.

Copy link

coderabbitai bot commented Feb 25, 2024

Walkthrough

The recent updates to the TestNG framework address a notable discrepancy in DataProvider behavior between versions 6.x and 7.x, specifically regarding data generation and caching for test retries. The changes introduce mechanisms to control whether data for retried tests should be reused or regenerated, enhancing flexibility and aligning with previous behavior. Additionally, enhancements include the ability to order TestNG listeners and the migration of Ant support.

Changes

Files Change Summary
.../IDataProviderMethod.java, .../annotations/DataProvider.java, .../annotations/IDataProviderAnnotation.java, .../internal/DataProviderMethod.java, .../internal/annotations/DataProviderAnnotation.java, .../internal/annotations/JDK15TagFactory.java, .../internal/invokers/TestInvoker.java Introduced mechanisms to control caching of data for test retries, aligning TestNG 7.x behavior with 6.x.
.../internal/Parameters.java Updated a URL in an error message related to dependency injection.
.../test/java/test/dataprovider/DataProviderTest.java, .../test/java/test/dataprovider/issue3041/SampleTestCase.java Added tests to validate new data provider caching behavior for test retries.
CHANGES.txt Documented fixes and new features, including listener ordering and the separation of Ant support.

Assessment against linked issues

Objective Addressed Explanation
DataProvider method should be called for every retry in TestNG tests. (#3041)
Clarification on handling scenarios with a multi-dimensional array of data and some tests fail. (#3041) The changes introduce control over data caching but do not explicitly address multi-dimensional arrays and partial test failures.
Introduction of a mechanism to indicate data should be regenerated on every retry. (#3041)
Resolution of discrepancy in DataProvider behavior between TestNG 6 and 7.x versions. (#3041)

Poem

In the world of code where tests often tread,
A rabbit hopped in, with changes widespread.
"Let's fix and align," it said with a cheer,
"DataProvider's quirks, now everything's clear."

With annotations new, and retries so fine,
Our rabbit ensured, each test could shine.
Through versions and features, it danced with glee,
🐰 "For better testing, follow me!"

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-tests for this file.
  • 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 tests 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 from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @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.

Closes testng-team#3041

We can now configure TestNG to enable/disable 
caching of test data produced by a data provider
when TestNG is retrying a failed test method using
the attribute “cacheDataForTestRetries” on the 
“@dataProvider” annotation.

Below is a sample, which forces TestNG to re-invoke
the data provider when a test method fails and it 
needs to be retried.

```
@dataProvider(name = "dp", cacheDataForTestRetries = false)
public Object[][] getData() {
  return new Object[][] {{1}, {2}};
}
```
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2cc332d and cc37588.
Files selected for processing (11)
  • CHANGES.txt (1 hunks)
  • testng-core-api/src/main/java/org/testng/IDataProviderMethod.java (1 hunks)
  • testng-core-api/src/main/java/org/testng/annotations/DataProvider.java (1 hunks)
  • testng-core-api/src/main/java/org/testng/annotations/IDataProviderAnnotation.java (1 hunks)
  • testng-core/src/main/java/org/testng/internal/DataProviderMethod.java (1 hunks)
  • testng-core/src/main/java/org/testng/internal/Parameters.java (1 hunks)
  • testng-core/src/main/java/org/testng/internal/annotations/DataProviderAnnotation.java (2 hunks)
  • testng-core/src/main/java/org/testng/internal/annotations/JDK15TagFactory.java (1 hunks)
  • testng-core/src/main/java/org/testng/internal/invokers/TestInvoker.java (2 hunks)
  • testng-core/src/test/java/test/dataprovider/DataProviderTest.java (1 hunks)
  • testng-core/src/test/java/test/dataprovider/issue3041/SampleTestCase.java (1 hunks)
Files skipped from review as they are similar to previous changes (11)
  • CHANGES.txt
  • testng-core-api/src/main/java/org/testng/IDataProviderMethod.java
  • testng-core-api/src/main/java/org/testng/annotations/DataProvider.java
  • testng-core-api/src/main/java/org/testng/annotations/IDataProviderAnnotation.java
  • testng-core/src/main/java/org/testng/internal/DataProviderMethod.java
  • testng-core/src/main/java/org/testng/internal/Parameters.java
  • testng-core/src/main/java/org/testng/internal/annotations/DataProviderAnnotation.java
  • testng-core/src/main/java/org/testng/internal/annotations/JDK15TagFactory.java
  • testng-core/src/main/java/org/testng/internal/invokers/TestInvoker.java
  • testng-core/src/test/java/test/dataprovider/DataProviderTest.java
  • testng-core/src/test/java/test/dataprovider/issue3041/SampleTestCase.java

@krmahadevan krmahadevan merged commit 823799c into testng-team:master Feb 26, 2024
8 of 9 checks passed
@krmahadevan krmahadevan deleted the fix/3041 branch February 26, 2024 02:00
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.

TestNG 7.x DataProvider works in opposite to TestNG 6.x when retrying tests.
2 participants