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

Retry analyzer not calling BeforeMethod & AfterMethods if firstTimeOnly/lastTimeOnly are mentioned for the test #792

Open
narulacool opened this issue Sep 3, 2015 · 6 comments

Comments

@narulacool
Copy link

Consider the case below:

@BeforeMethod(firstTimeOnly=true)
public void StartDriver()
{
   System.out.println("Start Driver");
}

@AfterMethod(lastTimeOnly=true)
public void stopDriver()
{
   System.out.println("Stop Driver");
}

@Test
public void TestRetry()
{
   Assert.assertTrue(false,"TestRetry Failed");
}

If I use TestNG's IRetryAnalyzer to rerun the above case, the StartDriver & stopDriver are called for the actual first run, while none of the two is called for the Second(retry) time.

[testng] Start Driver
[testng] [Status]:TestRetry2_FAIL
[testng] Stop Driver
[testng] Going to retry test case: TestRetry()
[testng] [Status]:TestRetry2_FAIL

I am using TestNG 6.9.4 & this works fine(i.e start & stop are called for both first time & for the retry execution) if firstTimeOnly & lastTimeOnly are not mentioned.

Any help would be deeply appreciated.

@narulacool
Copy link
Author

ping..

@prvn133t
Copy link

I guess this is working as designed. Looking at the code of public boolean firstTimeOnly() default false;

I see

If true and the @test method about to be run has an invocationCount > 1, this
BeforeMethod will only be invoked once (before the first test invocation).

So the invocationCount is already > 1 during the retry. So this is working as expected.

So your best bet would be not to use firstTimeOnly

@rschmitt
Copy link
Contributor

It does, however, look like the @AfterMethod is being called prematurely.

@prvn133t
Copy link

@rschmitt : Do you have a test? I can debug the code.

P.S : @AfterMethod is outside the scope of this issue

@rschmitt
Copy link
Contributor

Says who? Look at his console output again:

[testng] Start Driver
[testng] [Status]:TestRetry2_FAIL
[testng] Stop Driver
[testng] Going to retry test case: TestRetry()
[testng] [Status]:TestRetry2_FAIL

It's an invariant violation for the @AfterMethod here to run between tests, isn't it?

@prvn133t
Copy link

prvn133t commented Sep 14, 2015

@rschmitt : I totally agree what you're saying. All I'm saying is, this defect context doesn't reflect the actual bug in testng.

There should be a new defect for "Retry analyzer not calling BeforeMethod & AfterMethods if it's specified in a Test Class"

Example :

public class testBug {

@BeforeMethod()
public void StartDriver()
{
   System.out.println("Start Driver");
}

@AfterMethod()
public void stopDriver()
{
   System.out.println("Stop Driver");
}

@Test
public void TestRetry()
{
   Assert.assertTrue(false,"TestRetry Failed");
}

Now this won't call BeforeMethod and AfterMethod During 'RetryAnalyzer`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants