1

So I'm starting to use junit more and more and so more and more test-driven development, and I'm feeling pretty good about it.

However, I run into problems when attempting to test a user interface - my first instinct is for junit to create a robot that object that crontols the mouse and the keyboard to mimic a human working though a test - but that feels both inelegant and not very resilient to change. Am I approaching this all wrong? What's the best practice in this case?

The particular case I'm looking at is SWT-based, but any general overviews would be great :)

Joe
  • 4,367
  • 7
  • 33
  • 52

3 Answers3

2

I was about to suggest uispec4j. That, apparently, does not support SWT.

Almost all 'robot' based testing will be fragile- you may end up spending significant time in fixing tests if the GUI changes. if you planning to write a framework you could start from jemmy. This has a good model driven GUI testing feature. Jemmy cannot be directly used in junit tests, though.

Refactoring the UI for testing results in good design. If you are open to such an idea, try Model View Presenter pattern

Jayan
  • 18,003
  • 15
  • 89
  • 143
1

As it happens - it turns out that in the particular case (not in general, which is why I accepted the other answer) of swt - what I'm really looking for was http://www.eclipse.org/swtbot/

Joe
  • 4,367
  • 7
  • 33
  • 52
1

It depends what type of user interface you're testing, but for web testing, look at Selenium, which automates browsers, and allows you to navigate through sites etc.

For Swing testing, look at FEST, which does the same for swing applications.

For the actual testing of the interface, these represent the usual approaches, although I sometimes just call the web page directly using Apache HttpClient and look at the results directly (checking there is no error on the page for instance). This can often be simpler to set up and less fragile as a test.

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171