-1

I am writing some JUnit tests for my Java program. Some of these tests cause messages to pop up that stop the tests and require me to click ok for them to continue.

Is there a way I can programatically, from my test class, close the JDialog?

3
  • You could always make the classes under test not pop up JDialogs
    – user253751
    Mar 6, 2015 at 1:24
  • Well, I need the popups for the main program. Is there a way to disable them just for tests? Mar 6, 2015 at 1:24
  • If you make a way to disable them just for tests, then yes.
    – user253751
    Mar 6, 2015 at 1:36

1 Answer 1

1

It sounds like you need to adopt a better design pattern. You should be aiming to separate your testable business logic from your user interface.

In the long term, I'd recommend moving towards a design pattern such as model, view, presenter (MVP). All your business logic would exist in the presenter and this would be the layer to test.

As a short term solution, refactor your code so that any messages are handled by some kind of MessageHandler interface. In your product code, this will create real dialogs for the user to interact with. In your tests, you can mock the interface and verify it has been invoked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.