-2

*I created a project in eclipse that has several classes. I cant find a way to run all the classes in the package one by one. Is this possible?

The link below answers my question:

How to run two java files one by one- Eclipse?

1) make a new file src/testng.xml (or edit if already exist)

   <?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
   <suite name="Default suite">
   <test verbose="2" name="Default test">
      <classes>
         <class name="test.LoginOneReports"/>
       <class name="test.OEPR_DefaultTab"/>
    </classes>
 </test> <!-- Default test -->
 </suite> <!-- Default suite -->

2) Eclipse: Run \ Run Configurations... 'Test' tab, 'Suite' radiobutton, Browse. Choose your testng.xml file. Click Run.

however, I was not able to find my XML file using the listed path:

....'Test' tab, 'Suite' radiobutton, Browse. Choose your testng.xml file.

Hassan
  • 1
  • 1

1 Answers1

1

I created a project in eclipse that has several classes. I cant find a way to run all the classes in the package one by one. Is this possible?

I'm not sure quite what you are trying to test here. Are you looking to instantiate these classes, or make an object out of each of them? If this is the case, as long as the constructors aren't all set to private, you should be able to do this from the main method of any class in the same package, as your question states.

Example:

public class Test1 {

    public Test1() {
        System.out.println("Class 1");
    }

    public static void main(String[] args) {
        new Test1();
        new Test2();
        new Test3();
    }
}
...
public class Test2 {
    public Test2() {
        System.out.println("Class 2");
    }
}
...
public class Test3 {
    public Test3() {
        System.out.println("Class 3");
    }
}

Are you trying to access the entry point of each class, or the main static method in each? If this is the case, you can do something similar as above and access each from a single class.

Example:

public class Test1 {
    public static void main(String[] args) {
        System.out.println("Class 1");
        Test2.main(args);
        Test3.main(args);
    }
}
...
public class Test2 {
    public static void main(String[] args) {
        System.out.println("Class 2");
    }
}
...
public class Test3 {
    public static void main(String[] args) {
        System.out.println("Class 3");
    }
}

Or, if you are trying to run actual tests on your classes, this would be done through unit testing with JUnits. Unfortunately, I can't quite determine what you are asking. Try adding some more detail here or maybe what code you've come up with so far, or what classes you have. This will help others better answer your questions.

kennemat
  • 180
  • 2
  • 8