allure-framework / allure-java

Allure integrations for Java test frameworks
Apache License 2.0
341 stars 218 forks source link

🐞: ClassCastException when using TestNG 7.9.0 with use-global-thread-pool="true" #1013

Open Pavlo-Tiutiunnyk opened 4 months ago

Pavlo-Tiutiunnyk commented 4 months ago

What happened?

TestNg has recently released new version with a feature that allows using shared thread pool for all data driven and non data driven tests When using it with allure testng, the tests throws ClassCastException

Please see the examples attached

build.gradle

buildscript {
    ext {
        allureVersion = '2.25.0'
        aspectjVersion = '1.9.21.1'
        testngVersion = '7.9.0'
    }
}

plugins {
    id 'java'
    id 'idea'
    id "io.freefair.aspectj.post-compile-weaving" version "8.6"
    id 'io.qameta.allure' version '2.11.2'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    implementation("org.testng:testng:$testngVersion")
    implementation platform("io.qameta.allure:allure-bom:$allureVersion")
    implementation("io.qameta.allure:allure-testng:$allureVersion")
    implementation("org.aspectj:aspectjweaver:$aspectjVersion")
    implementation("org.aspectj:aspectjrt:$aspectjVersion")
}

task runOneTest(type: Test) {
    useTestNG() {
        suites "src/test/resources/test_suites/allure_testng_test.xml"
    }
}

test class

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.concurrent.ThreadLocalRandom;

public class AllureTestngTest {

    private static final int dataSize = 25;

    @Test(dataProvider = "dp")
    public void parallelDataDrivenTest1(int i) {

    }
    @Test(dataProvider = "dp")
    public void parallelDataDrivenTest2(int i) {

    }

    @DataProvider(name = "dp", parallel = true)
    public Object[][] getData() {
        Object[][] data = new Object[dataSize][1];
        for (int i = 0; i < dataSize; i++) {
            data[i][0] = ThreadLocalRandom.current().nextInt();
        }
        return data;
    }
}

testng xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.1.dtd" >

<suite name="Example suite" parallel="methods" use-global-thread-pool="true" thread-count="4">
    <test name="One Test">
        <classes>
            <class name="AllureTestngTest"/>
        </classes>
    </test>
</suite>

stack trace

class java.util.concurrent.CompletableFuture$AsyncSupply cannot be cast to class java.lang.Comparable (java.util.concurrent.CompletableFuture$AsyncSupply and java.lang.Comparable are in module java.base of loader 'bootstrap')
java.lang.ClassCastException: class java.util.concurrent.CompletableFuture$AsyncSupply cannot be cast to class java.lang.Comparable (java.util.concurrent.CompletableFuture$AsyncSupply and java.lang.Comparable are in module java.base of loader 'bootstrap')
    at java.base/java.util.concurrent.PriorityBlockingQueue.siftUpComparable(PriorityBlockingQueue.java:349)
    at java.base/java.util.concurrent.PriorityBlockingQueue.offer(PriorityBlockingQueue.java:475)
    at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1357)
    at java.base/java.util.concurrent.CompletableFuture.asyncSupplyStage(CompletableFuture.java:1782)
    at java.base/java.util.concurrent.CompletableFuture.supplyAsync(CompletableFuture.java:2005)
    at org.testng.internal.invokers.MethodRunner.runInParallel(MethodRunner.java:143)
    at org.testng.internal.invokers.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:950)
    at org.testng.internal.invokers.TestInvoker.invokeTestMethods(TestInvoker.java:201)
    at org.testng.internal.invokers.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:148)
    at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at org.testng.internal.thread.graph.TestNGFutureTask.run(TestNGFutureTask.java:22)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

What Allure Integration are you using?

allure-testng

What version of Allure Integration you are using?

2.25.0

What version of Allure Report you are using?

2.25.0

Code of Conduct