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

Updated Status in afterInvocation() not considered #1611

Merged
merged 1 commit into from
Nov 16, 2017

Conversation

krmahadevan
Copy link
Member

Closes #1600

Fixes #1600 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt

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.

Github1600Listener listener = new Github1600Listener();
TestListenerAdapter tla = new TestListenerAdapter();
tng.addListener((ITestNGListener) tla);
tng.addListener((ITestNGListener) listener);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just thinking a TestNG#addListeners(ITestNGListener... listeners) could be awesome.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its use would be limited to just us for writing our unit tests, and to those that use the TestNG APIs directly (perhaps the IDE plugins and the build tool plugins). I dont see much of a use for this in other places. But yes, I agree, it would be simple change.

@@ -1167,11 +1168,18 @@ private void handleInvocationResults(ITestNGMethod testMethod,
}
}

private static int computeTestStatusComparingTestResultAndStatusHolder(ITestResult testResult, StatusHolder holder,
boolean wasResultUnaltered) {
if (wasResultUnaltered) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand well. What are the value of holder.status and testResult.getStatus() before and after handleInvocationResults, and before/after your fix?

Maybe testResult.getStatus() == holder.status can replace wasResultUnaltered?

Copy link
Member Author

@krmahadevan krmahadevan Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No that wouldn't work. holder.status represents the computed status by us, taking into account the expectedExceptions attribute of an @Test annotation. So for an e.g., if an @Test method threw a org.testng.SkipException then its status would be FAILURE (because it threw an exception) but our computed status for holder.status would be SKIP (since we have a special meaning for SkipException).
So if we merely stuck to evaluating testResult.getStatus() == holder.status we end up using testResult.getStatus() which is incorrect.

The testResult.getStatus() value should be considered only if it was altered by the user defined IInvokedMethodListener implementations (which is what #1600 is asking for).

In all other cases, we should only consider holder.status

@juherr juherr requested a review from cbeust November 16, 2017 08:46
@cbeust cbeust merged commit 17185dd into testng-team:master Nov 16, 2017
@krmahadevan krmahadevan deleted the krmahadevan-fix-1600 branch November 17, 2017 04:33
@xlenz
Copy link

xlenz commented Nov 30, 2017

Since 6.13 throw new SkipException("Skipping the test case"); won't work. I have to set status before throwing exception:

iTestResult.setStatus(TestResult.SKIP);
throw new SkipException("Skipping the test case");

Just want to make sure :)

@juherr
Copy link
Member

juherr commented Nov 30, 2017

It doesn't shock me in the listener context and I think it is a better practice.
BTW, it is a regression, so can you open a new issue?

@xlenz
Copy link

xlenz commented Nov 30, 2017

@juherr It is a regression, but I'm not sure if it is a planned change or not.
Let me clarify...
previously I had in beforeInvocation:
throw new SkipException("Skipped due to previous failure of: " + failedTestName);
So I have TestResult.SKIP in afterInvocation.

After upgrading to 6.13 it stopped working, because iTestResult.getStatus() is now TestResult.FAILURE instead of TestResult.SKIP in afterInvocation.

@juherr
Copy link
Member

juherr commented Nov 30, 2017

Regressions are never expected :)

And TestNG should be able to catch the skip exception and set the status accordingly.

A new issue is a better location for the discussion and we will be able to close it if we want ;)

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.

Updated in afterInvocation() testResult.status is not used in willRetry condition
4 participants