@@ -508,52 +508,49 @@ private static void setTestStatus(ITestResult result, int status) {
508
508
private static class StatusHolder {
509
509
510
510
boolean handled = false ;
511
+ int originalStatus ;
511
512
int status ;
512
513
}
513
514
514
- private void handleInvocationResults (
515
+ private void handleInvocationResult (
515
516
ITestNGMethod testMethod ,
516
517
ITestResult testResult ,
517
518
FailureContext failure ,
518
519
StatusHolder holder ,
519
- boolean wasResultUnaltered ) {
520
- //
521
- // Go through all the results and create a TestResult for each of them
522
- //
523
- List <ITestResult > resultsToRetry = Lists .newArrayList ();
524
-
525
- Throwable ite = testResult .getThrowable ();
526
- int status =
527
- computeTestStatusComparingTestResultAndStatusHolder (testResult , holder , wasResultUnaltered );
528
- boolean handled = holder .handled ;
529
- IRetryAnalyzer retryAnalyzer = testMethod .getRetryAnalyzer (testResult );
530
-
531
- boolean willRetry =
532
- retryAnalyzer != null
533
- && status == ITestResult .FAILURE
534
- && failure .instances != null
535
- && retryAnalyzer .retry (testResult );
520
+ boolean willRetry ) {
536
521
537
522
if (willRetry ) {
538
- resultsToRetry .add (testResult );
539
523
Object instance = testResult .getInstance ();
540
524
if (!failure .instances .contains (instance )) {
541
525
failure .instances .add (instance );
542
526
}
543
527
testResult .setStatus (ITestResult .SKIP );
544
528
testResult .setWasRetried (true );
545
529
} else {
546
- testResult .setStatus (status );
547
- if (status == ITestResult .FAILURE && !handled ) {
530
+ testResult .setStatus (holder . status );
531
+ if (holder . status == ITestResult .FAILURE && !holder . handled ) {
548
532
int count = failure .count ++;
549
533
if (testMethod .isDataDriven ()) {
550
534
count = 0 ;
551
535
}
552
- handleException (ite , testMethod , testResult , count );
536
+ handleException (testResult . getThrowable () , testMethod , testResult , count );
553
537
}
554
538
}
555
539
}
556
540
541
+ private boolean shouldRetryTestMethod (
542
+ ITestNGMethod testMethod ,
543
+ ITestResult testResult ,
544
+ FailureContext failure ,
545
+ StatusHolder holder ) {
546
+ IRetryAnalyzer retryAnalyzer = testMethod .getRetryAnalyzer (testResult );
547
+
548
+ return retryAnalyzer != null
549
+ && holder .status == ITestResult .FAILURE
550
+ && failure .instances != null
551
+ && retryAnalyzer .retry (testResult );
552
+ }
553
+
557
554
// pass both paramValues and paramIndex to be thread safe in case parallel=true + dataprovider.
558
555
private ITestResult invokeMethod (
559
556
TestMethodArguments arguments , XmlSuite suite , FailureContext failureContext ) {
@@ -597,7 +594,8 @@ private ITestResult invokeMethod(
597
594
testResult .setMethod (arguments .getTestMethod ());
598
595
invokedMethod = new InvokedMethod (startTime , result );
599
596
invokeListenersForSkippedTestResult (result , invokedMethod );
600
- runAfterGroupsConfigurations (arguments , suite , testResult );
597
+ runAfterConfigurations (arguments , suite , testResult );
598
+ runAfterGroupsConfigurations (arguments );
601
599
602
600
return result ;
603
601
}
@@ -699,11 +697,12 @@ private ITestResult invokeMethod(
699
697
StatusHolder holder =
700
698
considerExceptions (
701
699
arguments .getTestMethod (), testResult , expectedExceptionClasses , failureContext );
702
- int statusBeforeListenerInvocation = testResult .getStatus ();
703
700
runInvokedMethodListeners (AFTER_INVOCATION , invokedMethod , testResult );
704
- boolean wasResultUnaltered = statusBeforeListenerInvocation == testResult .getStatus ();
705
- handleInvocationResults (
706
- arguments .getTestMethod (), testResult , failureContext , holder , wasResultUnaltered );
701
+ updateStatusHolderAccordingToTestResult (testResult , holder );
702
+ boolean willRetryMethod =
703
+ shouldRetryTestMethod (arguments .getTestMethod (), testResult , failureContext , holder );
704
+ handleInvocationResult (
705
+ arguments .getTestMethod (), testResult , failureContext , holder , willRetryMethod );
707
706
708
707
// If this method has a data provider and just failed, memorize the number
709
708
// at which it failed.
@@ -730,7 +729,10 @@ private ITestResult invokeMethod(
730
729
731
730
collectResults (arguments .getTestMethod (), testResult );
732
731
733
- runAfterGroupsConfigurations (arguments , suite , testResult );
732
+ runAfterConfigurations (arguments , suite , testResult );
733
+ if (!willRetryMethod ) {
734
+ runAfterGroupsConfigurations (arguments );
735
+ }
734
736
735
737
// Reset the test result last. If we do this too early, Reporter.log()
736
738
// invocations from listeners will be discarded
@@ -740,13 +742,15 @@ private ITestResult invokeMethod(
740
742
return testResult ;
741
743
}
742
744
743
- private void runAfterGroupsConfigurations (
745
+ private void runAfterConfigurations (
744
746
TestMethodArguments arguments , XmlSuite suite , TestResult testResult ) {
745
747
ITestNGMethod [] teardownConfigMethods =
746
748
TestNgMethodUtils .filterTeardownConfigurationMethods (
747
749
arguments .getTestMethod (), arguments .getAfterMethods ());
748
750
runConfigMethods (arguments , suite , testResult , teardownConfigMethods );
751
+ }
749
752
753
+ private void runAfterGroupsConfigurations (TestMethodArguments arguments ) {
750
754
GroupConfigMethodArguments grpArgs =
751
755
new GroupConfigMethodArguments .Builder ()
752
756
.forTestMethod (arguments .getTestMethod ())
@@ -795,50 +799,51 @@ public ITestResult registerSkippedTestResult(
795
799
796
800
private StatusHolder considerExceptions (
797
801
ITestNGMethod tm ,
798
- ITestResult testresult ,
802
+ ITestResult testResult ,
799
803
ExpectedExceptionsHolder exceptionsHolder ,
800
804
FailureContext failure ) {
801
805
StatusHolder holder = new StatusHolder ();
802
- holder . status = testresult .getStatus ();
806
+ int status = testResult .getStatus ();
803
807
holder .handled = false ;
804
808
805
- Throwable ite = testresult .getThrowable ();
806
- if (holder . status == ITestResult .FAILURE && ite != null ) {
809
+ Throwable ite = testResult .getThrowable ();
810
+ if (status == ITestResult .FAILURE && ite != null ) {
807
811
808
812
// Invocation caused an exception, see if the method was annotated with @ExpectedException
809
813
if (exceptionsHolder != null ) {
810
814
if (exceptionsHolder .isExpectedException (ite )) {
811
- testresult .setStatus (ITestResult .SUCCESS );
812
- holder . status = ITestResult .SUCCESS ;
815
+ testResult .setStatus (ITestResult .SUCCESS );
816
+ status = ITestResult .SUCCESS ;
813
817
} else {
814
818
if (isSkipExceptionAndSkip (ite )) {
815
- holder . status = ITestResult .SKIP ;
819
+ status = ITestResult .SKIP ;
816
820
} else {
817
- testresult .setThrowable (exceptionsHolder .wrongException (ite ));
818
- holder . status = ITestResult .FAILURE ;
821
+ testResult .setThrowable (exceptionsHolder .wrongException (ite ));
822
+ status = ITestResult .FAILURE ;
819
823
}
820
824
}
821
825
} else {
822
- handleException (ite , tm , testresult , failure .count ++);
826
+ handleException (ite , tm , testResult , failure .count ++);
823
827
holder .handled = true ;
824
- holder . status = testresult .getStatus ();
828
+ status = testResult .getStatus ();
825
829
}
826
- } else if (holder . status != ITestResult .SKIP && exceptionsHolder != null ) {
830
+ } else if (status != ITestResult .SKIP && exceptionsHolder != null ) {
827
831
TestException exception = exceptionsHolder .noException (tm );
828
832
if (exception != null ) {
829
- testresult .setThrowable (exception );
830
- holder . status = ITestResult .FAILURE ;
833
+ testResult .setThrowable (exception );
834
+ status = ITestResult .FAILURE ;
831
835
}
832
836
}
837
+ holder .originalStatus = testResult .getStatus ();
838
+ holder .status = status ;
833
839
return holder ;
834
840
}
835
841
836
- private static int computeTestStatusComparingTestResultAndStatusHolder (
837
- ITestResult testResult , StatusHolder holder , boolean wasResultUnaltered ) {
838
- if (wasResultUnaltered ) {
839
- return holder .status ;
842
+ private static void updateStatusHolderAccordingToTestResult (
843
+ ITestResult testResult , StatusHolder holder ) {
844
+ if (holder . originalStatus != testResult . getStatus () ) {
845
+ holder .status = testResult . getStatus () ;
840
846
}
841
- return testResult .getStatus ();
842
847
}
843
848
844
849
private class MethodInvocationAgent {
0 commit comments