I'm not sure what testing library (if any) you are using to execute the tests; I'm going to assume jUnit here, because that's what most people use for testing in Java. Similarly, I'm not sure if you're using ant or maven with this project.
Using JUnit
You can invoke the JUnit test runner from the command line using the following:
java -cp .:/usr/share/java/junit.jar junit.textui.TestRunner [classname]
for JUnit 3.x, or
java -cp .:/usr/share/java/junit.jar org.junit.runner.JUnitCore [classname]
for 4.x
However, this will only run one class full of tests, and you indicated wanting to run multiple. The way you string together multiple test classes into a single unit to execute in JUnit is by using a suite,like follows:
/**
* All smoke tests in one easy suite!
*
*/
@RunWith(Suite.class)
@SuiteClasses({ FooSmokeTests.class,
BarSmokeTests.class,
BazSmokeTests.class})
public class AllSmokeTests {
}
Then you can run AllSmokeTests (which is the name of my test suite) with either of the above commands (depending on your JUnit version), and it will execute FooSmokeTests, BarSmokeTests, and BazSmokeTests in turn.
Using Maven
If your project is built with Maven, you can also execute the tests using maven itself. First, ensure that your pom.xml indicates which tests to run:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>smokeTests/AllSmokeTests.java</include>
</includes>
</configuration>
</plugin>
That "include" line tells it to run AllSmokeTests (the suite I made above) by default, and nothing else. You can have multiple includes here to run multiple files, or if you make a suite like I did, you can put the suite here. Or you can put multiple suites. The sky is the limit!
Then, from the command line, inside the directory where your pom.xml is, just run mvn test
. This will build and run your tests.
Using ant
I always use Maven for my test projects, but ant should have similar capabilities using the jUnit task. I found the following on StackOverflow:
<property name="target.dir" value="${basedir}/target"/>
<property name="main.destdir" value="${target.dir}/classes"/>
<property name="test.srcdir" value="${basedir}/src/test/java"/>
<property name="test.destdir" value="${target.dir}/test-classes"/>
<!-- Execute all classfiles you've compiled in test-classes directory -->
<junit fork="true"
maxmemory="128m"
includeAntRuntime="true">
<classpath>
<pathelement path="${main.destdir}"/>
<pathelement path="${test.destdir}"/>
</classpath>
<classpath refid="test.classpath"/>
<formatter type="plain"/>
<batchtest
todir="${junit.batchtest.todir}">
<fileset dir="${test.destdir}"/>
</batchtest>
</junit>
This is set up to run every test class, which is a common setup; presumably, you could also target that to a specific test class and run that, or run multiple.
Using vanilla Java
If you're not using jUnit at all, but just have your code in a method, you can set up a main() method with the signature public static void main(String [] args)
. Then you can execute the code with something like java -jar myJar
to execute the main method inside the compiled jar myJar. You might need to edit the manifest if eclipse didn't update it; see this documentation for more details.