I want to rerun a test class including its @BeforeMethod
when any one of it's @Test
fails. I have already implemented TestNG retry logic to rerun the failed test cases but I want to run entire class.
相关问题
- TestNG report with customized error in place of st
- TESTNG: how to send emailable report as an email
- org.testng.TestNGException: sun.security.provider.
- Combining 2 reports into one 1 in (testng) allure
- Debugging TestNG configuration failures
相关文章
- TestNG skipping tests - why?
- How to test a Validator which implements Constrain
- Is it safe to use DateTimeUtils.setCurrentMillisFi
- How to use @FindBy annotation in Selenium WebDrive
- use verify on mocked (with Mockito) objects inject
- How to run TestNG suite with failsafe without unpa
- How to install TestNG eclipse plugin offline?
- TetsNG SoftAssert with Hamcrest matcher
Please, take a look: http://testng.org/doc/documentation-main.html#rerunning all failed tests are included to the separate xml suite, that can be rerun.
It is possible to do so. For this you need to register an implementation of org.testng.ITestListener in testNg.xml as a listener
OnTestFailureClass
must implementorg.testng.ITestListener
.Implement onTestFailure as follows:
CAUTION
You must have a good reason to rerun the test. Rerunning of the test must be desired when you know for sure that the second iteration will result in success. If this is not the case, then you will enter an infinite loop, wherein a failing tests will keep on getting executed and getting failed.
In addition, if you want to run a test case only n number of times irrespective of the test result, then you will have to build a logic for counter in the
onTestFailure
method.-----------------------------UPDATE------------------------------------
Discovered a more elegant solution Implement IRetryAnalyzer interface. This interface has been provided by TestNG specifically for the purpose of retrying a failed test. It provided the number of times the retry must be done.
you need use following annotations
However, to avoid adding this attribute to your all test methods take the following approach which is referred by this link 'TestNG retryAnalyzer only works when defined in methods @Test, does not work in class' @Test'
This should hopefully provide you with testng-results.xml report.