apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.66k stars 851 forks source link

Running tests with TestNG fails #6737

Open matty-r opened 11 months ago

matty-r commented 11 months ago

Apache NetBeans version

Apache NetBeans 19

What happened

Attempt to run tests with TestNG installed in the classpath, I get the following error

Exception in thread "main" org.testng.TestNGException: Couldn't find a constructor in class org.testng.reporters.VerboseReporter                 at org.testng.internal.objects.InstanceCreator.newInstance(instancecreator.java:57)                 at org.testng.ITestObjectFactory.newInstance(itestobjectfactory.java:10)

....

How to reproduce

Install TestNG with required dependencies and run a test.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows

JDK

17

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

It works correctly if I run the test via a Test Runner, but if I right click and select run file or test file it throws that error. I narrowed it down to the TestNGAntTask in the build-impl.XML file where the listeners attribute has the VerboseReporter package listed - if I remove that it works.

Are you willing to submit a pull request?

No

matty-r commented 11 months ago

I've been able to reproduce this on two separate machines.

All libraries are in the classpath:

image

Error message:

Couldn't find a constructor in class org.testng.reporters.VerboseReporter
    at org.testng.internal.objects.InstanceCreator.newInstance(InstanceCreator.java:57)
    at org.testng.ITestObjectFactory.newInstance(ITestObjectFactory.java:10)
    at org.testng.TestNG.setListenerClasses(TestNG.java:684)
    at org.testng.TestNG.configure(TestNG.java:1549)
    at org.testng.TestNG.privateMain(TestNG.java:1431)
    at org.testng.TestNG.main(TestNG.java:1404)

This is there the VerboseReporter is referenced in the build-impl.xml

    <target if="${testng.available}" name="-init-macrodef-testng">
        <macrodef name="testng" uri="http://www.netbeans.org/ns/j2se-project/3">
            <attribute default="${includes}" name="includes"/>
            <attribute default="${excludes}" name="excludes"/>
            <attribute default="**" name="testincludes"/>
            <attribute default="" name="testmethods"/>
            <element name="customize" optional="true"/>
            <sequential>
                <condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}">
                    <isset property="test.method"/>
                </condition>
                <union id="test.set">
                    <fileset dir="${test.tests.dir}" excludes="@{excludes},**/*.xml,${excludes}" includes="@{includes}">
                        <filename name="@{testincludes}"/>
                    </fileset>
                </union>
                <taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
                <testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="urchat" testname="TestNG tests" workingDir="${work.dir}">
                    <xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
                    <propertyset>
                        <propertyref prefix="test-sys-prop."/>
                        <mapper from="test-sys-prop.*" to="*" type="glob"/>
                    </propertyset>
                    <classpath>
                        <path path="${run.test.classpath}"/>
                    </classpath>
                    <jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
                    <customize/>
                </testng>
            </sequential>
        </macrodef>
    </target>