I have a testNG framework that I was asked to make runnable via the command line. I’ve added the code to execute the tests, but part of the command line execution was passing in the test class to be executed. Java doesn’t seem to like this.
My Code:
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
try
{
Class cl = Class.forName(myClass);
testng.setTestClasses(new Class[] { cl.class });
testng.addListener(tla);
testng.run();
}
catch (Exception ex)
{
...
}
The variable myClass is one of the arguments passed into Main.
I receive an error on the “cl.class” code of “unknown class”.
What would be the proper way of doing this?
EDIT:
When actually building the project, the error returned is “error: cannot find symbol class cl”.
the issue may be that you are putting cl.class in your Class array. cl is a class object. Try
You can read more about the Class class here http://docs.oracle.com/javase/tutorial/reflect/class/classNew.html