Reputation: 66
I have to write a program that run JUnit test case from a user interface.
I found that I can use JUnitCore
class to run tests with method:
junit.run(class files);
but this requires the .class file containing the tests. I need to obtain the .class files having only a path of a directory that contains the JUnit .java files but I don't know how to get reference to these and use them with the run() method. Any suggestion? Thanks in advance
EDIT
As it has been pointed out I don't need the .class files but an instance of Class for every java file in the directory. How can I get it?
EDIT 2
Just solved with parsing the path of file and using the Class.forname(String)
method!
Upvotes: 0
Views: 640
Reputation: 21184
If all you have is the raw source (.java) files you're going to have to compile them before being able to reference them .class files. This question should tell you how to do that programmatically
Upvotes: 1