testng-team / testng-eclipse

Eclipse plug-in for TestNG
https://testng.org
193 stars 164 forks source link

@Parameters cannot use static variable in array #555

Closed youming-lin closed 1 year ago

youming-lin commented 1 year ago

Problem Statement

please read https://github.com/cbeust/testng-eclipse/blob/master/docs/Troubleshooting.md first Example code:

package test;

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class TestNGEclipseBug {
    private static final String PROPERTY = "property";

    public TestNGEclipseBug() {
        System.setProperty("property", "Hello world!");
    }

    @Parameters({ PROPERTY }) // An internal error occurred during: "Launching TestNGEclipseBug.testBug".
    // @Parameters(PROPERTY) // no error
    // @Parameters({ "property" }) // no error
    // @Parameters("property") // no error
    @Test
    public void testBug(final String property) {
        System.out.println(property);
    }
}

Using @Parameters({ PROPERTY }) would cause error when running the test:

Screenshot 2023-08-02 at 10 21 55 AM
An internal error occurred during: "Launching TestNGEclipseBug.testBug".
class org.eclipse.jdt.core.dom.SimpleName cannot be cast to class org.eclipse.jdt.core.dom.StringLiteral (org.eclipse.jdt.core.dom.SimpleName and org.eclipse.jdt.core.dom.StringLiteral are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @6fa15c7b)

Code compiles, but test cannot run in Eclipse using this plugin. Based on the error message it seems to be issue with Eclipse plugin instead of TestNG itself.

No error if static variable is used by itself (as opposed to wrapped inside array), or if string literal is used instead (array or not).

Similar(same?) issue reported back in 2018: https://github.com/testng-team/testng-eclipse/issues/294#issuecomment-387052780

Any relate message in "Error Log" view

"Windows -> Show View -> Others -> Error Log"

The Dependency Management tool for your project

Operating System

missedone commented 1 year ago

@youming-lin , thanks for reporting the issue, i can reproduce it with your sample, let me see if i can fix it quickly

missedone commented 1 year ago

issue fixed, pls update to the latest version 7.8.0.202308061717

youming-lin commented 1 year ago

@missedone Thank you for fixing this so fast! Downloaded the latest plugin version and I can confirm using static var in array works now.