vendredi 6 avril 2018

Too many parallel JFrames open at once - how to close them at JUnit test end?

I would like to ask about a simple thing - I am testing a JUnit-based GUI and have a problem - once I run the test suite, it opens a new JFrame GUI for each test - but only closes all of them at once after all tests have finished.

This is ok for tens of tests, but I need to run 1000s of test cases overnight and Java (and probably the OS) will not allow me to open 1000s of GUI interfaces at once - and it would slow down the computation too probably.

I have tried to close the GUI at the end of the test case, but it doesn't seem to work... Any ideas would be appreciated.

This is the test case:

@Test(timeout=1000)
public void mainTest1() throws Exception {
    String[] args={"False","0","35","10","25","0","1"};
    calc A=new calc();
    A.main(args);
    double expected=0.0;
    System.out.println("Test result: "+A.result_BMI+"; Expected: "+expected);
    assertTrue(A.result_BMI==expected);
    A.closeGui();
}

This is the closeGui() function I used:

public void closeGui(){
    //close GUI
    this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
}

Aucun commentaire:

Enregistrer un commentaire