Vinee
Vinee

Reputation: 402

JUNIT runner Not able to identify the class name

I am trying to execute a list of JUNIT test cases through JUNIT runner. The test case names are available in a excel sheet and I am retreiving the value one after the other.

I am not sure where I am going wrong. but my test runner is not executing. Could somebody help me on this.

Cell celltest = sheet.getCell(col,row);
String KeywordTest=celltest.getContents().concat(strClass);
//org.junit.runner.JUnitCore.runClasses(MyJUNITTestCase.class);
org.junit.runner.JUnitCore.runClasses(KeywordTest);

If I try the commented line, it is working fine. But if I try to retreive the values from an excel and store it to the "KeywordTest". The runclasses is not recognising it. Any idea where i went wrong.

Upvotes: 0

Views: 768

Answers (1)

Matthew Farwell
Matthew Farwell

Reputation: 61705

JUnitCore#runClasses takes a Class..., so you can't just pass a String to it like you're doing. You need to take the string "com.foo.bar.Foobar" and convert it into a class, as follows:

org.junit.runner.JUnitCore.runClasses(Class.forName(KeywordTest));

Please note that in java, variables usually start with a lower case letter, as follows:

Cell celltest = sheet.getCell(col,row);
String keywordTest=celltest.getContents().concat(strClass);
org.junit.runner.JUnitCore.runClasses(Class.forName(keywordTest));

And also, the keywordTest needs to be fully qualified. Foobar by itself won't work, you need com.foo.bar.Foobar.

Upvotes: 1

Related Questions