I was able to make it work by having a regular class
call my Test Suite Class
which calls my JUnit Test Classes
. I don't know why it wasn't working before, but this time when I tried to export and there was a new option there.
Solution Below
JUnit test suite class (runs all the test classes I put into @SuiteClasses, called by 'TestRunner' class)
package myPackageName;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ TestClass1.class, TestClass2.class })
public class AllTests {
}
TestRunner Class, the class that is exported into the executable jar. This was the missing piece, without it, export would not work.
package myPackageName;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(AllTests.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
}
}
Export Steps
- Click File, Click Export
- Open java Folder, Click 'Runnable JAR file', Click next
- Launch Configuration drop down shows an option 'myPackageName - TestRunner'. This is where I was able to pick the class that contains the main method that will be run by the JAR. (the issue I was having before, it wasn't there and if I selected other classes that appeared it gave an export error).
- I used the 'package required libraries into generated JAR' option for library handling, I think its correct because I have selenium libraries.
- Click Finish
- Run JAR by opening windows explorer and clicking it. Or, open CMD, cd to file directory, and run
java -jar myJarName.jar
.