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

Fix issue #857 #860

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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) {
System.out.println("FAILURE");
failedTests.add(result);
}

@Override
public void onTestSkipped(ITestResult result) {
System.out.println("SKIPPED");
skippedTests.add(result);
}

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

@Override
public void onTestStart(ITestResult result) {
System.out.println("START");
}

@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;
}
}
25 changes: 25 additions & 0 deletions src/test/java/test/retryAnalyzer/github857/GitHub857Sample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package test.retryAnalyzer.github857;

import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import static org.testng.Assert.fail;

@Listeners(GitHub857Listener.class)
public class GitHub857Sample {

@BeforeTest(alwaysRun = true)
public void beforeTest(ITestContext context) {
for (ITestNGMethod method : context.getAllTestMethods()) {
method.setRetryAnalyzer(new GitHub857Retry());
}
}

@Test
public void test() {
fail("Failing");
}
}