Skip to content

Commit

Permalink
Add test case for testng-team#857
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Herr committed Nov 5, 2015
1 parent 2c12573 commit 789b22b
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/test/java/test/retryAnalyzer/RetryAnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.testng.annotations.Test;

import test.SimpleBaseTest;
import test.retryAnalyzer.github857.GitHub857Listener;
import test.retryAnalyzer.github857.GitHub857Sample;

public class RetryAnalyzerTest extends SimpleBaseTest {
@Test
Expand All @@ -34,4 +36,27 @@ public void testInvocationCounts() {
List<ITestResult> skipped = tla.getSkippedTests();
assertEquals(skipped.size(), InvocationCountTest.invocations.size() - fsp.size());
}

@Test(description = "GITHUB-857: onTestFailure not being called when test is retried")
public void onTestFailureShouldBeCalledWhenTestIsRetried() {
TestNG tng = create(GitHub857Sample.class);
TestListenerAdapter tla = new TestListenerAdapter();
tng.addListener(tla);

tng.run();

assertEquals(tla.getPassedTests().size(), 0);
assertEquals(tla.getFailedButWithinSuccessPercentageTests().size(), 0);
assertEquals(tla.getSkippedTests().size(), 1);
assertEquals(tla.getSkippedTests().get(0).getMethod().getMethodName(), "test");
assertEquals(tla.getFailedTests().size(), 1);
assertEquals(tla.getFailedTests().get(0).getMethod().getMethodName(), "test");

assertEquals(GitHub857Listener.passedTests.size(), 0);
assertEquals(GitHub857Listener.failedButWSPerTests.size(), 0);
assertEquals(GitHub857Listener.skippedTests.size(), 1);
assertEquals(GitHub857Listener.skippedTests.get(0).getMethod().getMethodName(), "test");
assertEquals(GitHub857Listener.failedTests.size(), 1);
assertEquals(GitHub857Listener.failedTests.get(0).getMethod().getMethodName(), "test");
}
}
54 changes: 54 additions & 0 deletions src/test/java/test/retryAnalyzer/github857/GitHub857Listener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package test.retryAnalyzer.github857;

import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.TestListenerAdapter;
import org.testng.collections.Lists;

import java.util.Collections;
import java.util.List;

public class GitHub857Listener extends TestListenerAdapter {

public static List<ITestResult>
passedTests =
Collections.synchronizedList(Lists.<ITestResult>newArrayList());
public static List<ITestResult>
failedTests =
Collections.synchronizedList(Lists.<ITestResult>newArrayList());
public static List<ITestResult>
skippedTests =
Collections.synchronizedList(Lists.<ITestResult>newArrayList());
public static List<ITestResult>
failedButWSPerTests =
Collections.synchronizedList(Lists.<ITestResult>newArrayList());

@Override
public void onTestSuccess(ITestResult result) {
passedTests.add(result);
}

@Override
public void onTestFailure(ITestResult result) {
failedTests.add(result);
}

@Override
public void onTestSkipped(ITestResult result) {
skippedTests.add(result);
}

@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
failedButWSPerTests.add(result);
}

@Override
public void onTestStart(ITestResult result) {}

@Override
public void onStart(ITestContext context) {}

@Override
public void onFinish(ITestContext context) {}
}
19 changes: 19 additions & 0 deletions src/test/java/test/retryAnalyzer/github857/GitHub857Retry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test.retryAnalyzer.github857;

import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;

public class GitHub857Retry implements IRetryAnalyzer {

private static final int MAX_RETRY_COUNT_PER_TEST = 1;
private int retryCountPerTest = 0;

@Override
public boolean retry(ITestResult result) {
if (retryCountPerTest < MAX_RETRY_COUNT_PER_TEST) {
retryCountPerTest++;
return true;
}
return false;
}
}
15 changes: 15 additions & 0 deletions src/test/java/test/retryAnalyzer/github857/GitHub857Sample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package test.retryAnalyzer.github857;

import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import static org.testng.Assert.fail;

@Listeners(GitHub857Listener.class)
public class GitHub857Sample {

@Test(retryAnalyzer = GitHub857Retry.class)
public void test() {
fail("Failing");
}
}

0 comments on commit 789b22b

Please sign in to comment.