question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ITestListener/onTestFailure Not doing anything

See original GitHub issue

TestNG Version

7.5

Expected behavior

ITestListener picks up failed tests and performs a screenshot. Previously worked on 7.4.0

Actual behavior

Test not being detected as failed, so inside methods not being ran.

Is the issue reproducible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

This code previous to 7.5 would run and perform the methods within. When I update to 7.5 the listener doesn’t seem to pick up the tests even though the listener is stated on every class. Has something changed?

Test classes are using Annotation @Listeners({TestListener.class})

package TestListeners;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class TestListener1 implements ITestListener {

    @Override
    public void onTestFailure(ITestResult iTestResult){
        System.out.println("Test has failed");
    }

}

Test

package TestListeners;

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

@Listeners({TestListener1.class})
public class SimpleTestFailure {

    @Test
    public void sampleTest() {
        throw new AssertionError("force fail");
    }

}

Output:

java.lang.AssertionError: force fail

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
krmahadevancommented, Jan 14, 2022

@garyc0221 i can try taking a jab at it since I am a selenium literate.

Can you please create a sample project and attach it here which uses all the dependencies that your actual project has and which has a failing test along with a failure listener that takes screenshots?

Keep it as close to your actual project as possible so that we are looking at a replica of your actual project.

0reactions
garyc0221commented, Jan 14, 2022

@garyc0221 - Then I think you would need to take this up with Allure. So we can perhaps go ahead and close this out ?

Yes can close this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

CustomListener's onTestFailure not ran when test fails
I am trying to get TestNG to do something when test fails using custom listener. I obtain TestNG instance with getDefault and I...
Read more >
Attachment is not working when TestListener is in testng.xml
Attachment annotation and addAttachment helper method are not working when the TestListener class is added in testng.xml and not in a Test class ......
Read more >
OnTestSucess is not working in TestNG Listeners
Hi Ashish,. I have already registered listener in testng.xml because onTestFailure is working fine only I found issue in onTestSuccess. Thanks.
Read more >
Override onTestFailure - Google Groups
I'm having some trouble overriding a method "onTestFailure" from "TestListenerAdapter". ... Thks for the replay Cedric but its not working.. >.<
Read more >
TestNG Listeners in Selenium: ITestListener & ITestResult ...
OnStart- OnStart method is called when any Test starts. ... onTestFailure- onTestFailure method is called on the failure of any Test.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found