How to execute JUnit package inside a jar

I have a project where one single package contains all the JUnit tests. (But this is not in src / test, but in src / main). In the eclipse environment, I can select a package and work like JUnit. It will then execute the classes in alphabetical order. But now I want to do the same but use the built jar. How should I do it? (on the command line)

+3


source to share


1 answer


The closest solution to this problem I can think of is to add the class of the class to your src code and run suite

from the command line. If you want, you can use the dynamic class lookup, which cpsuite

gives you and does the following (this will also be more general and doesn't involve adding the class to your project):

Write a jar with this class:

import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.extensions.cpsuite.ClasspathSuite.IncludeJars;
import org.junit.runner.RunWith;

@RunWith(ClasspathSuite.class)
@IncludeJars(true)
public class MySuite {
}

      



Include this jar in your classpath and do something like this from the command line:

java -cp <path-to-where MySuite jar>:<path-to-tested-jar + all its dependencies>:<path-to cpsuite.jar + all its dependencies> org.junit.runner.JUnitCore <full-package-name-to-where-MySuite-is-in>.MySuite

      

+2


source







All Articles