2

I am using eclipse and need to test many files for my application. This mean, I have to go to: `run -> run configurations -> arguments', change them and re-run, for about 30 different test files.

Is there a quicker way to do this? I have googled java automated testing. Just need some guidance, I am abit confused.

thanks daniel

dgamma3
  • 2,333
  • 4
  • 26
  • 47
  • 3
    can't you put parameters in a property file ? So the launch config will be just one and you'll be able to change params editing the prop file. – BigMike Sep 08 '15 at 08:18
  • 4
    Now would be a good time to learn about unit testing... there are *lots* of resources out there... (Assuming you really are talking about testing, rather than batch processing.) – Jon Skeet Sep 08 '15 at 08:21
  • 1
    if you are using a tomcat in your eclipse may be [this](http://stackoverflow.com/questions/12407163/pass-vm-argument-to-apache-tomcat) will help you. – Imran Sep 08 '15 at 08:23

2 Answers2

1

You should setup a Maven project or an ant build file to perform a suite of tests in one click rather than going one by one as you currently do.

Otherwise you can simply put all the tests you want to run in a specific package or folder then select : "Run all tests in the selected project, package or source folder" in the JUnit Run/debug configuration :

RunDebug conf

Another way with Eclipse is to create a test suite :

  • Open the New wizard
  • Select Java > JUnit > JUnit Test Suite and click Next.
  • Enter a name for your test suite class
  • Select the classes that should be included in the suite.

Test Suite

aleroot
  • 71,077
  • 30
  • 176
  • 213
0

if it's just command line variations, you can sort it out adding a simple class like this (wrote this on the fly without a javac, may have errors)

public class PropertyRunner {
    private static String commands [] = {"TEST_1", "TEST_2", "TEST_3" };

    public static void main(String[] args) throws FileNotFoundException, IOException
    {
        Properties config = new Properties();
        config.load(new FileInputStream("config.props"));
        // config.props contains all my tests in the format:
        // TEST_1=-a|-k|ccccc
        // TEST_2=-b|-k|ccccd
        // TEST_3=-c|-k|FEFEF

        // now run test cases:
        for (String key : commands) {
            String cmdLine = config.getProperty(key);
            // cmdLine is in format "-a|-b|ccccc"
            String childArgs[] = cmdLine.split("\\|");
            // Exec your main class passing args directly or via threads
            // YourApp.main(childArgs);
        }
        System.exit(0);
    }
}

It's pretty simple, you store all your command lines in a property file, and then iterate on every key executing your real main class and passing the arguments read from the property file.

BigMike
  • 6,683
  • 1
  • 23
  • 24