Reputation: 143
I would like to run a JUnitTest on a .java file which is not in the project folder. So far I implemented running the test succesfully if the .java file which should be tested is in the project folder:
public Result testAStudent(Class aTestClass){
Result r = org.junit.runner.JUnitCore.runClasses(aTestClass);
return r;
}
How can I run the test on a file which is not in my project folder? I found a possibility to do it in the shell, but I do not want to execute shell commands. Is there a way to do it "internal"? Thank you!
Upvotes: 0
Views: 1577
Reputation: 691625
Unit tests allow testing compiled class files. Not .java
source files. For the test to be able to use (and thus test) a given class, this class must be available in the classpath.
So, when launching JUnit, make sure to have the directory or jar file containing the classes to test in the classpath.
Upvotes: 2