This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Testing the UI

 
S Saunders
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My team this year decided to experiment with unit testing. I found it to be quite helpful during our development. However some of my tasks dealt mostly with the creation of the user interface. I found that I had a difficult time creating JUnit tests for this. In fact, we decided to not write tests that dealt with the UI. Could those who have had experience with this eloborate on the following questions.
What are the possibilities for testing?
Is it possible to use JUnit for these tests?
And finally,
Should I go to the trouble of creating the Java event objects to use in my tests?
Thanks,
Steve
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,
Do you use an AWT/Swing UI or an HTML/JSP UI?
If it is an AWT/Swing UI, you can test the underlying model. There are probably ways of testing the actual UI, but I'm not sure what they are.
If it is an HTML/JSP UI, you can use Mock Objects and JWebUnit to test the session/request objects and layout.
 
S Saunders
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We use an AWT/Swing UI. You mentioned testing of the underlying model, what does this entail? I am new to testing and am trying to grasp the terminology and philosophies.
Steve
Originally posted by Jeanne Boyarsky:
Steve,
Do you use an AWT/Swing UI or an HTML/JSP UI?
If it is an AWT/Swing UI, you can test the underlying model. There are probably ways of testing the actual UI, but I'm not sure what they are.
If it is an HTML/JSP UI, you can use Mock Objects and JWebUnit to test the session/request objects and layout.
 
Vincent Massol
Author
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by S Saunders:
My team this year decided to experiment with unit testing. I found it to be quite helpful during our development. However some of my tasks dealt mostly with the creation of the user interface. I found that I had a difficult time creating JUnit tests for this. In fact, we decided to not write tests that dealt with the UI. Could those who have had experience with this eloborate on the following questions.
What are the possibilities for testing?
Is it possible to use JUnit for these tests?
And finally,
Should I go to the trouble of creating the Java event objects to use in my tests?
Thanks,
Steve

You can have a look at http://www.junit.org/news/extension/gui/index.htm
I've tried Abbot and it's quite nice.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,
Suppose you are displaying a table in a Swing program. You can check that the table has the correct values, number of rows/columns, ... While this doesn't check everything, it's better than nothing. I remember reading an article with a good example of this, but now I can't find it.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is also an entry in our FAQ: http://test.javaranch.com/wiki/view?UnitTestingGuis
 
S Saunders
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Steve,
Suppose you are displaying a table in a Swing program. You can check that the table has the correct values, number of rows/columns, ... While this doesn't check everything, it's better than nothing. I remember reading an article with a good example of this, but now I can't find it.

So you are suggesting a "traditional" test check of the UI components. I agree that this is important. I would be interested in the article if you remember or even if you remember the publication/website would be good.
Thanks,
Steve
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So you are suggesting a "traditional" test check of the UI components. I agree that this is important. I would be interested in the article if you remember or even if you remember the publication/website would be good.

You can also easily test all the event-handling code if you don't tie it tightly to the GUI components. For example, any non-trivial event handlers ought to look like this:

Where "handler" is a reference to a non-graphical object. Now the "complicated..." method can be tested isolated from the GUI itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic