0

I have test class as shown below that uses hardcoded parameters in input function to initialize tests:

@RunWith(Parameterized.class)
public class Test1 extends JUnitXMLReporter {
    private String name, id, platform, version;
    private Test1 test;

    public Test1(String name, String id, String platform, String version){
        //super();
        this.name = name;
        this.id = id;
        this.platform = platform;
        this.version = version;
    }

    @Test
    //Login as test user | start menu | logout
    public void testLoginLogout() {
        [...]
    }

    @Before
    public void initialize() {
        test = new Test1(name, id, platform, version);
    }

    @Parameterized.Parameters
    public static String[][] input() {
        return new String[][]{{"Nexus 5X API 24", "emulator-5554", "Android", "7.0"},
                              {"Nexus 5X API 26", "emulator-5556", "Android", "8.0"}};
    }

}

I know that I can call this class so Result result = JUnitCore.runClasses(new ParallelComputer(false, true), Test1.class); to run @Test in parallel for hardcoded parameters. Now I want to change it so now hardcoded information is read from file and preferably passed from main So preferably main would read XML file to get info, put it in array and pass to Test class. How can I achieve that?

Uliysess
  • 579
  • 1
  • 8
  • 19
  • 1
    Possible duplicate of [Junit parameterized tests using file input](https://stackoverflow.com/questions/21401504/junit-parameterized-tests-using-file-input) – Nicholas K Aug 09 '18 at 14:29
  • Said thread doesn't explain how to pass read arguments from main to Test class, but explains how to possibly easy read file. Thank you – Uliysess Aug 09 '18 at 14:35

1 Answers1

0

With help of @Nikolas from comments that pointed reading file procedure I finally used globals System.setProperty("name") and System.getProperty("name"). Example:

testClass

//class name & annotation β†’ @RunWith(Parameterized.class)
private String name, id, platform, version;
private testClass test;

public testClass(String name, String id, String platform, String version){
    //super();
    this.name = name;
    this.id = id;
    this.platform = platform;
    this.version = version;
}

@Test
//whatever test

@Before
public void initialize() {
    test = new testClass(name, id, platform, version);
}

@Parameterized.Parameters( name = "{2}, {0}")
public static String[][] input() {
    return differentClass.input();
}

differentClass.input()

//function reading file and returning correct type, here String[][]
//most important is↓
//File file = new File(System.getProperty("devices"));
Uliysess
  • 579
  • 1
  • 8
  • 19