-
Notifications
You must be signed in to change notification settings - Fork 1k
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
How to rerun skipped test cases using TestNG? #3126
Comments
@Kaveeshhh - Can you please help me understand as to what exactly are you trying to achieve here? A test method can be skipped due to the following reasons:
Please help answer the following questions:
|
@krmahadevan You're right about the limitations of retrying skipped tests with dependencies. However, for independent test cases that skip due to failures in @BeforeSuite, @BeforeTest, @BeforeClass, or @BeforeMethod annotations, we might not need to pinpoint the exact cause. In this scenario, would it be possible using TestNG to achieve a mechanism that simply retries the entire test class? |
@Kaveeshhh - When a test skips due to a configuration failure, TestNG does not tell you as to which config method failure caused the test to be skipped. So we wouldn't be able to run the actual required pre-requisites for a skipped test to be retried.
No. The current implementation doesnt have any way of doing this from within TestNG. |
On the other hand if you would like to retry a failed configuration method (just to rule out flakiness in the setup for e.g.,) you can try doing something like below: import org.testng.IConfigurable;
import org.testng.IConfigureCallBack;
import org.testng.ITestResult;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class AnotherSample implements IConfigurable {
private boolean fail = true;
@Override
public void run(IConfigureCallBack callBack, ITestResult testResult) {
callBack.runConfigurationMethod(testResult);
if (!testResult.isSuccess()) {
fail = false;
callBack.runConfigurationMethod(testResult);
}
}
@BeforeClass
public void beforeClass() {
if (fail) {
throw new RuntimeException();
}
}
@Test
public void test() {
System.err.println("Hello world");
}
} In the sample, we are doing the following:
Note: This will handle only configuration retries |
@krmahadevan, I modified your code by defining the maximum retry count, but now I have an issue where the before class retry mechanism is getting triggered even for successful tests. Do you have any solutions for that?
|
@Kaveeshhh - I would suggest that you spend time debugging this issue. The problem seems to be in your logic. @juherr - I personally feel that we can close this issue because the ask of re-running a skipped test doesn't seem to be a valid one IMO. Your thoughts ? |
Hi @krmahadevan, Thank you for your feedback. I understand that the logic may need adjustment. Here is a more detailed explanation of the issue I'm encountering: I have implemented a retry mechanism by defining the maximum retry count in my code. However, I've observed that the beforeClass method's retry mechanism is being triggered even for tests that pass successfully. Based on your suggestion, I reviewed the logic and attempted to debug the issue. However, I am still experiencing the problem where beforeClass is being executed multiple times even when the tests pass successfully. Could you please provide more specific guidance or suggest modifications to the current implementation to resolve this issue? Thank you for your assistance. |
You can try |
Closing this issue with resolution as "Question Answered" |
TestNG Version
7.4.0
Expected behavior
I want to re-run testng skipped test cases.
Actual behavior
Getting 'Test ignored.' message.
Is the issue reproducible on runner?
Test case sample
Contribution guidelines
Incase you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.
The text was updated successfully, but these errors were encountered: