File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Unit testing applets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Unit testing applets" Watch "Unit testing applets" New topic
Author

Unit testing applets

Allan Halme
Ranch Hand

Joined: Aug 22, 2003
Posts: 62
I've inherited an applet that needs quite a bit of work. There are no unit tests. My question is, how to write unit tests for applets? What frameworks are there available?
Naturally, as much of the applet's code as possible should be placed into separate classes (that don't inherit java.applet.Applet), and thus those can easily be unit tested with JUnit.
However, there's still the concrete descendant of java.applet.Applet to test -- what options are there for this? Consider that there's already a couple of thousand lines of code implementing the applet, with no unit tests. I'd like to write unit tests to confirm the current behaviour of the applet, then I can happily refactor, making sure that all unit tests keep running.
[ January 15, 2004: Message edited by: Allan Halme ]
[ January 15, 2004: Message edited by: Allan Halme ]

<i>The lyf so short, the craft so long to lerne.</i> --Geoffrey Chaucer (c. 1343-1400)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Try instantiating the Applet class (possibly into a JFrame if it doesn't work alone), calling "doClick()" etc on whatever active elements you have in the GUI, and verify that the expected changes occurred in whatever panels/tables/lists you have.
And let us know if that (or something else) worked


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I would advice to write Acceptance Tests instead of Unit Tests. Those are much less dependend on the internal structure of the application.
Take a look at http://fitnesse.org/ for a free tool.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Does Fit(nesse) have built-in fixtures for testing applets? That would be an interesting (not to mention challenging) feature.
Allan Halme
Ranch Hand

Joined: Aug 22, 2003
Posts: 62
Acceptance testing is a good thing, but in this case, what I want to do is unit test the internal workings of the applet. It's just that right now it's a big monolithic chunk ...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Unit testing applets