reportportal / agent-java-testNG

TestNG listener
Apache License 2.0
54 stars 20 forks source link

Launch not finished if testng SkipException thrown in Before/After methods #28

Closed daroshchanka closed 5 years ago

daroshchanka commented 6 years ago

Seems, SkipException in Before/After methods not handled correctly.

Problem actual for Before/After Suite, Before/After Test, Before/After Class, Before/After Method. Before/After Group not tested.

1 Test launch hangs and not finished

2 Counfiguration methods duplicated

image error.log

image

        <dependency>
            <groupId>com.epam.reportportal</groupId>
            <artifactId>agent-java-testng</artifactId>
            <version>4.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.epam.reportportal</groupId>
            <artifactId>logger-java-log4j</artifactId>
            <version>4.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version> //6.11 the same
        </dependency>

To Reproduce (groovy code)

import com.epam.reportportal.testng.ReportPortalTestNGListener
import org.testng.SkipException
import org.testng.annotations.BeforeClass
import org.testng.annotations.Listeners

@Listeners([ReportPortalTestNGListener])
class Test {

    @BeforeClass
    public void before(){
        throw new SkipException("text")
    }

    @org.testng.annotations.Test
    public void test1(){
        sleep(1000)
    }

    @org.testng.annotations.Test
    public void test2(){
        sleep(1000)
    }

    @org.testng.annotations.Test
    public void test3(){
        sleep(1000)
    }

}
evjlobanova commented 6 years ago

@avarabyeu could you please look at this issue?

daroshchanka commented 6 years ago

Hi, @avarabyeu. I just removed the line with startConfiguration https://github.com/reportportal/agent-java-testNG/blob/854985c1488e6548ce69fedf24a61472d3f35abb/src/main/java/com/epam/reportportal/testng/BaseTestNGListener.java#L124

This fix works for us.

class MyReportPortalTestNGListener extends BaseTestNGListener {

    //static instance with lazy init
    private static final Supplier<ITestNGService> SERVICE = Suppliers.memoize(new Supplier<ITestNGService>() {
        @Override
        public ITestNGService get() {
            return new TestNGService()
        }
    });

    public MyReportPortalTestNGListener() {
        super(SERVICE.get())
    }

    @Override
    public void onConfigurationSkip(ITestResult testResult) {
        SERVICE.get().finishTestMethod(Statuses.SKIPPED, testResult)
    }
}

I checked fix under several projects, no side effects detected. Is this line needed? :)

avarabyeu commented 6 years ago

@daroshchanka yeah, the line is needed for reporting method as skipper. Thank a lot for raising it up!

filland commented 5 years ago

@daroshchanka Hello, i fixed the problem. Here is the branch with the fix - https://github.com/reportportal/agent-java-testNG/tree/issue28 Could you try it with your tests ?

daroshchanka commented 5 years ago

@filland Works for me.

filland commented 5 years ago

@daroshchanka this fix is already in the latest published version

NiliMe commented 5 years ago

@filland It is not working for me on version 7.0.0-beta6. SkipException on any Before method (before class, before suite, before method) makes the execution to stuck.

In the attached capture we can see that the method "getTmsVersionprintCurrentClass" (whice is annotated @BeforeClass) is stuck on InProgress, and so are all the Before methods after it (the methods "deleteAllMockDcs" & "temp" are @Test annotated but also didn't run properly. testng stuck

filland commented 5 years ago

@NiliMe this might happen since the agent using testng 6.14.3

NiliMe commented 5 years ago

@filland which agent is it? How can I upgrade the Testng version? I'm running using Intellij (latest version) and surefire plugin (2.19.1)

filland commented 5 years ago

@NiliMe the latest version of reportportal testng agent developed using testng 6.14.3. I am going to investigate the reason why it does not work with testng 7.0.0.*. I also recommend you to not use 7th version of testng (if possible) since it is in beta stage.