JUnit - stop it from exiting on finish?

前端 未结 4 643
旧巷少年郎
旧巷少年郎 2021-01-19 22:34

Quick JUnit question. I\'m running some unit tests that involve starting up the GUI and doing a load of stuff.

I would like to see the results after the test to conf

4条回答
  •  鱼传尺愫
    2021-01-19 23:02

    Due to the fact you require a GUI and user interaction during the execution of the test, this is a "functional" test rather than a "unit" test.

    You could write the results to a file at the end, this would have the added benefit that you could assert that the output is correct/present programatically at the end. If you really want to keep the test running, then you could insert an infinite loop at the end of your test:

    JUnit 3:

    public void tearDown() {
        while (true) { Thread.sleep(2000); };
    }
    

    JUnit 4:

    @After
    public void tearDown() {
        while (true) { Thread.sleep(2000); };
    }
    

    This will keep the JUnit thread running, but you will need to ensure that your GUI events are being handled in another thread.

提交回复
热议问题