-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy test result attributes when unexpected failures
Closes #3064
- Loading branch information
1 parent
1774b2c
commit e77f1c2
Showing
6 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
testng-core/src/test/java/test/listeners/issue3064/EvidenceListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package test.listeners.issue3064; | ||
|
||
import org.testng.ITestListener; | ||
import org.testng.ITestResult; | ||
|
||
public class EvidenceListener implements ITestListener { | ||
public static final String ATTRIBUTE_KEY = "attributeKey"; | ||
public static ITestResult failureTestResult; | ||
|
||
@Override | ||
public void onTestStart(ITestResult result) { | ||
result.setAttribute(ATTRIBUTE_KEY, "attributeValue"); | ||
} | ||
|
||
@Override | ||
public void onTestFailure(ITestResult result) { | ||
failureTestResult = result; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
testng-core/src/test/java/test/listeners/issue3064/EvidenceRetryAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package test.listeners.issue3064; | ||
|
||
import org.testng.IRetryAnalyzer; | ||
import org.testng.ITestResult; | ||
|
||
public class EvidenceRetryAnalyzer implements IRetryAnalyzer { | ||
|
||
public EvidenceRetryAnalyzer() { | ||
throw new RuntimeException("Failed on purpose"); | ||
} | ||
|
||
@Override | ||
public boolean retry(ITestResult result) { | ||
return false; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
testng-core/src/test/java/test/listeners/issue3064/SampleTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package test.listeners.issue3064; | ||
|
||
import static org.testng.Assert.fail; | ||
|
||
import org.testng.ITestContext; | ||
import org.testng.ITestNGMethod; | ||
import org.testng.Reporter; | ||
import org.testng.annotations.BeforeSuite; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
@Test | ||
@Listeners(EvidenceListener.class) | ||
public class SampleTestCase { | ||
|
||
@BeforeSuite(alwaysRun = true) | ||
public void suiteSetup() { | ||
ITestContext context = Reporter.getCurrentTestResult().getTestContext(); | ||
for (ITestNGMethod method : context.getAllTestMethods()) { | ||
method.setRetryAnalyzerClass(EvidenceRetryAnalyzer.class); | ||
} | ||
} | ||
|
||
@Test | ||
public void testOne() { | ||
fail(); | ||
} | ||
} |