简体   繁体   中英

How to run classes inside Jar file?

I created a jar file that launches an application to allow the user to select which test they want to run. Each test has its own class and main method. The UI application passes parameters to the main method for the class that represents the test.

I was able to create the executable JAR file for the UI application but nothing happens when I select the test I want to run. I think it is that JAR file can only handle one main method.

Below is part of the code for the application that allows the user to select which test to run.

public class UI extends JFrame {

    String[] args={Environment, Browser, TestingCoverage, DBLog, "UI"};

    if (chckbxEQ_CA_Home.isSelected())
    {   
        EQ_CA_Home.main(args);      
    }

    if (chckbxEQ_CA_Condo.isSelected())
    {               
        EQ_CA_Condo.main(args);
    }

    if (chckbxEQ_CA_Renter.isSelected())
    {   
        EQ_CA_Renter.main(args);
    }
}       

You can do that using Junit library.

JUnitCore junit = new JUnitCore();
Result res = junit.run(yourTestClass);

Don't invoke the main() method to avoid any possible interruptions, just let the JUnitcore find the appropriate test methods.

And also don't forget to include Junit.jar in classpath (or) include it as part of your jar file (as a fat jar).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM