0

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!

Marco
  • 66
  • 1
  • 1
  • 6
  • 3
    You are misinterpreting the docs; you should be passing instances of `Class` to this method. – Oliver Charlesworth Sep 07 '14 at 12:32
  • How can i get it? If I try to use the .getClass() method from a file I get only the type object at runtime (File class in this example). Sorry for my ignorance. – Marco Sep 07 '14 at 12:45

1 Answers1

1

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

Community
  • 1
  • 1
tddmonkey
  • 20,798
  • 10
  • 58
  • 67
  • Thanks for the reply but as Oli Charlesworth pointed out I've misinterpreted the docs. I don't need anymore the .class files. My problem now is how to get an instance of Class from each .java file in a directory. – Marco Sep 07 '14 at 16:18