Reputation:
I am a total beginner in Java and TestNG. I have a question (because I'm confused) regarding working of annotations in TestNG. I learned that Java annotations were added to Java 1.5. TestNG too supports annotations, and there are several annotations available in TestNG.
My confusion is that does TestNG annotations work because Java (version 1.5 or later) support annotations or they have their own support?
I mean if Java didn't have support for annotations, would TestNG annotations have worked then?
Upvotes: 1
Views: 196
Reputation: 4586
Of couse it will not work.
TestNG itself uses Java's annotations.
You can have a look at TestNG's source for example here.
It uses imports like
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
which will not work for JVM version <= 5.
I have used an old Java SE Development Kit and the oldest version of TestNG hosted here.
Have tried to run this:
import org.testng.annotations.Test;
public class TestClass {
@Test
public void testMethod() {
System.out.println("In the test method.");
}
}
Result:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
...
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:120)
Upvotes: 2