Closed himanshusoni30 closed 2 years ago
@himanshusoni30 hi, you may want to check the README's part about IAnnotationTransformer first.
@sskorol thanks for your prompt reply. I have tried below implementation as mentioned in IAnnotationTransformer
public class TestNGIAnnotationTransformerListener implements IAnnotationTransformerInterceptor {
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
List<TestRunManager> list = Reader.of(Sampledata.class).
from(new File("SampleData.xlsx").
sheet("sheet0").list();
list.stream().filter(l -> l.getTestCase().equalsIgnoreCase(testMethod.getName())).forEach(
l -> {
if(l.getExecute().equals(Boolean.TRUE)){
annotation.setEnabled(true);
annotation.setInvocationCount(l.getInvocationCount());
annotation.setPriority(l.getPriority());
}else{
annotation.setEnabled(false);
}
}
);
}
}
created a file io.github.sskorol.core.IAnnotationTransformerInterceptor inside src/main/resources/META-INF/services path
added fully qualified class name org.example.listeners.TestNGIAnnotationTransformerListener
(implementation class of IAnnotationTransformerInterceptor interface) in the above file
ran test from testng.xml
OUTPUT:
java.lang.ClassCastException: class org.example.listeners.TestNGIAnnotationTransformerListener cannot be cast to class org.testng.ITestNGListener (org.example.listeners.TestNGIAnnotationTransformerListener and org.testng.ITestNGListener are in unnamed module of loader 'app')
at org.testng.TestNG.addListeners(TestNG.java:964)
at org.testng.TestNG.initializeConfiguration(TestNG.java:924)
at org.testng.TestNG.initializeEverything(TestNG.java:1012)
at org.testng.TestNG.run(TestNG.java:1023)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Are you using Java9+ modules? Can you share your build config and module.info then.
@sskorol please find the contents of pom.xml below
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>exampleproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<env>test</env>
<suiteXmlFile>testng.xml</suiteXmlFile>
<app>example</app>
<seleniumwd.version>4.1.2</seleniumwd.version>
<testng.version>7.4.0</testng.version>
<maven-surefire.version>3.0.0-M5</maven-surefire.version>
<testdatasupplier.version>1.9.7</testdatasupplier.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
</properties>
<!-- Dependencies -->
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${seleniumwd.version}</version>
</dependency>
<dependency>
<groupId>io.github.sskorol</groupId>
<artifactId>test-data-supplier</artifactId>
<version>${testdatasupplier.version}</version>
</dependency>
</dependencies>
<!-- Build Plugin Management -->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<propertyName>${env}</propertyName>
<propertyName>${app}</propertyName>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@himanshusoni30 I checked your code. Your transformer is syntactically broken. You have the wrong number of parentheses. This code shouldn't even compile.
The other issue I see is types' misusage.
List<TestRunManager> list = Reader.of(Sampledata.class)
Here you read into Sampledata.class
but expect TestRunManager
as an output. It'd theoretically work only if TestRunManager
is an interface implemented by Sampledata.class
(or a parent class). But I don't see any real benefits of doing this yet.
The other question is in the way you read data from within a transformer. A library already provides a wrapper that does some internal tweaks for reading excel files. And you actually use this style in @DataSupplier
body. So I'd refactor the transformer the following way to be consistent:
public class TestNGIAnnotationTransformerListener implements IAnnotationTransformerInterceptor {
@Override
public void transform(
final ITestAnnotation annotation,
final Class testClass,
final Constructor testConstructor,
final Method testMethod
) {
use(XlsxReader.class)
.withTarget(SampleData.class)
.read()
.filter(test -> testMethod.getName().equalsIgnoreCase(test.getTestCaseName()))
.forEach(test -> {
annotation.setEnabled(test.shouldExecute());
annotation.setInvocationCount(test.getInvocationCount());
annotation.setPriority(test.getPriority());
});
}
}
Assuming your SampleData.class
looks like the following:
@Data
@Source(path = "data/sample.xlsx")
@Sheet(name = "Sheet1")
public class SampleData {
@Column(name = "TC", index = 0)
private String testCaseName;
@Column(name = "Execute", index = 1, converterClass = BooleanConverter.class)
private boolean execute;
@Column(name = "InvocationCount", index = 2, converterClass = IntegerConverter.class)
private int invocationCount;
@Column(name = "Priority", index = 3, converterClass = IntegerConverter.class)
private int priority;
public boolean shouldExecute() {
return execute;
}
}
Note that in the above code Lombok library is used to simplify POJOs handling.
Also, make sure you removed the listener's reference from testng.xml
, as you already defined SPI for your transformer class.
And a final note: when you read from the excel file, chances are there will be empty rows that may produce potential NPE. See #109 for details. So I'd reverse the order when you compare method names.
Well, technically, the tests' skipping issue is already addressed in TestNG 7.6.0. They introduced a new data provider flag propagateFailureAsTestFailure
that marks the test as failed in case of an exception thrown from the data provider. But this feature will be available only in the next release of test-data-supplier.
By the way, I noticed another issue. Your pom.xml
doesn't have aspectj
agent configured:
<properties>
<aspectj.version>1.9.9.1</aspectj.version>
</properties>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M6</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
</plugin>
hi @sskorol , i have made the suggested changes. Previous error is fixed but getting "java.lang.reflect.InvocationTargetException" now.
Please find the details below:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>exampleproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<env>test</env>
<suiteXmlFile>testng.xml</suiteXmlFile>
<app>example</app>
<seleniumwd.version>4.1.2</seleniumwd.version>
<testng.version>7.6.0</testng.version>
<maven-surefire.version>3.0.0-M6</maven-surefire.version>
<testdatasupplier.version>1.9.7</testdatasupplier.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
<aspectj.version>1.9.9.1</aspectj.version>
</properties>
<!-- Dependencies -->
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${seleniumwd.version}</version>
</dependency>
<dependency>
<groupId>io.github.sskorol</groupId>
<artifactId>test-data-supplier</artifactId>
<version>${testdatasupplier.version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>${aspectj.version}</version>
</dependency>
</dependencies>
<!-- Build Plugin Management -->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<propertyName>${env}</propertyName>
<propertyName>${app}</propertyName>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire.version}</version>
<configuration>
<argLine>
-javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
</argLine>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
public class TestNGIAnnotationTransformerListener implements IAnnotationTransformerInterceptor {
@Override
public void transform(
final ITestAnnotation annotation,
final Class testClass,
final Constructor testConstructor,
final Method testMethod
) {
use(XlsxReader.class)
.withTarget(SampleData.class)
.withSource("data/SampleData.xlsx")
.read()
.filter(test -> testMethod.getName().equalsIgnoreCase(test.getTestCaseName()))
.forEach(test -> {
annotation.setEnabled(test.shouldExecute());
annotation.setInvocationCount(test.getInvocationCount());
annotation.setPriority(test.getPriority());
});
}
}
@Data
@Sheet(name = "Sheet1")
public class SampleData {
@Column(name = "TC", index = 0)
private String testCaseName;
@Column(name = "Execute", index = 1, converterClass = BooleanConverter.class)
private boolean execute;
@Column(name = "InvocationCount", index = 2, converterClass = IntegerConverter.class)
private int invocationCount;
@Column(name = "Priority", index = 3, converterClass = IntegerConverter.class)
private int priority;
public boolean shouldExecute() {
return execute;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestSuite">
<listeners>
<!--<listener
class-name="org.example.listeners.TestNGIAnnotationTransformerListener"/>-->
</listeners>
<test verbose="2" preserve-order="true" name="test">
<classes>
<class name="org.example.test.RunTest">
<methods>
<include name="testRun" />
</methods>
</class>
</classes>
</test>
</suite>
ran test from testng.xml
OUTPUT
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.initializeForJava11(ClassLoaderWeavingAdaptor.java:1069)
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.defineClass(ClassLoaderWeavingAdaptor.java:1096)
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.access$300(ClassLoaderWeavingAdaptor.java:66)
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor$SimpleGeneratedClassHandler.acceptClass(ClassLoaderWeavingAdaptor.java:150)
at org.aspectj.weaver.tools.WeavingAdaptor$WeavingClassFileProvider$1.acceptResult(WeavingAdaptor.java:916)
at org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1430)
at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1192)
at org.aspectj.weaver.tools.WeavingAdaptor.getWovenBytes(WeavingAdaptor.java:549)
at org.aspectj.weaver.tools.WeavingAdaptor.weaveClass(WeavingAdaptor.java:385)
at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:115)
at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:51)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:244)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:541)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1217)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
at org.testng.TestNG.addServiceLoaderListeners(TestNG.java:1017)
at org.testng.TestNG.initializeConfiguration(TestNG.java:951)
at org.testng.TestNG.initializeEverything(TestNG.java:1048)
at org.testng.TestNG.run(TestNG.java:1059)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: java.lang.IllegalAccessException: module java.base does not open java.lang to unnamed module @3b07a0d6
at java.base/java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:259)
... 40 more
java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Method.invoke(Object, Object[])" because "org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.bindTo_Method" is null
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.defineClass(ClassLoaderWeavingAdaptor.java:1099)
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.access$300(ClassLoaderWeavingAdaptor.java:66)
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor$SimpleGeneratedClassHandler.acceptClass(ClassLoaderWeavingAdaptor.java:150)
at org.aspectj.weaver.tools.WeavingAdaptor$WeavingClassFileProvider$1.acceptResult(WeavingAdaptor.java:916)
at org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1430)
at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1192)
at org.aspectj.weaver.tools.WeavingAdaptor.getWovenBytes(WeavingAdaptor.java:549)
at org.aspectj.weaver.tools.WeavingAdaptor.weaveClass(WeavingAdaptor.java:385)
at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:115)
at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:51)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:244)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:541)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1217)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
at org.testng.TestNG.addServiceLoaderListeners(TestNG.java:1017)
at org.testng.TestNG.initializeConfiguration(TestNG.java:951)
at org.testng.TestNG.initializeEverything(TestNG.java:1048)
at org.testng.TestNG.run(TestNG.java:1059)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
[AppClassLoader@251a69d7] warning define generated class failed -- (NullPointerException) Cannot invoke "java.lang.reflect.Method.invoke(Object, Object[])" because "org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.bindTo_Method" is null
Cannot invoke "java.lang.reflect.Method.invoke(Object, Object[])" because "org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.bindTo_Method" is null
java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Method.invoke(Object, Object[])" because "org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.bindTo_Method" is null
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.defineClass(ClassLoaderWeavingAdaptor.java:1099)
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.access$300(ClassLoaderWeavingAdaptor.java:66)
at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor$SimpleGeneratedClassHandler.acceptClass(ClassLoaderWeavingAdaptor.java:150)
at org.aspectj.weaver.tools.WeavingAdaptor$WeavingClassFileProvider$1.acceptResult(WeavingAdaptor.java:916)
at org.aspectj.weaver.bcel.BcelWeaver.weaveAndNotify(BcelWeaver.java:1430)
at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:1192)
at org.aspectj.weaver.tools.WeavingAdaptor.getWovenBytes(WeavingAdaptor.java:549)
at org.aspectj.weaver.tools.WeavingAdaptor.weaveClass(WeavingAdaptor.java:385)
at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:115)
at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:51)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:244)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:541)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1217)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
at org.testng.TestNG.addServiceLoaderListeners(TestNG.java:1017)
at org.testng.TestNG.initializeConfiguration(TestNG.java:951)
at org.testng.TestNG.initializeEverything(TestNG.java:1048)
at org.testng.TestNG.run(TestNG.java:1059)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
java.util.ServiceConfigurationError: org.testng.ITestNGListener: io.github.sskorol.core.DataProviderTransformer Unable to get public no-arg constructor
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:586)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:679)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1240)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
at org.testng.TestNG.addServiceLoaderListeners(TestNG.java:1017)
at org.testng.TestNG.initializeConfiguration(TestNG.java:951)
at org.testng.TestNG.initializeEverything(TestNG.java:1048)
at org.testng.TestNG.run(TestNG.java:1059)
at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)
Caused by: java.lang.NoClassDefFoundError: io/github/sskorol/core/DataProviderTransformer$AjcClosure1
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3373)
at java.base/java.lang.Class.getConstructor0(Class.java:3578)
at java.base/java.lang.Class.getConstructor(Class.java:2271)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:666)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:663)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:674)
... 10 more
Caused by: java.lang.ClassNotFoundException: io.github.sskorol.core.DataProviderTransformer$AjcClosure1
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 18 more
I see several issues here:
And finally, the exception says:
Caused by: java.lang.IllegalAccessException: module java.base does not open java.lang to unnamed module @3b07a0d6
So it means you need to add the following to your maven-surefire-plugin argLine:
--add-opens java.base/java.lang=ALL-UNNAMED
It's hard to say which unnamed module requires this. But it should fix your issue.
@sskorol i am very grateful to you for helping me out with the above issues. I have made the changes as per your suggestions and achieved to use data-supplier library successfully in my project. Appreciate you for your valuable time, feedback, and patience :)
TestNG could not recognise the name of DataSupplier annotated method while running test from testng.xml using IAnnotationTransformer listener.
@Test(dataProvider="testDataReader")
is called from the testng.xml, then exception "org.testng.TestNGException: Method public void RunTest.testRun(org.example.datapojo.Sampledata) requires a @DataProvider named : testDataReader" is returned.Please refer Other Information section for more details.
I'm submitting
Environment
Is the issue reproducible on a runner?
What is the expected behavior?
. TestNG should be able recognise the name of DataSupplier annotated method while running test from testng.xml using IAnnotationTransformer listener.
What is the actual behavior?
. "org.testng.TestNGException: Method public void RunTest.testRun(org.example.datapojo.Sampledata) requires a @DataProvider named : testDataReader"
Other information
. Steps to reproduce issue
org.example.base.BaseTest
org.example.test.RunTest
org.example.datapojo.Sampledata
testng.xml
StackTrace