views:

92

answers:

4

Hi,

I'm looking to Unit Test a Swing application and was wondeing what would eb the best(easiest) approach to achieve this objective with almost full line coverage. If it matters, I'm using Eclipse Galileo for developemnt.

Thanks.

+2  A: 

Your question is quite general, so it is difficult to give concrete answer. Anyway, I try :-)

I understand that the code is already written, so practically you are working with legacy code. A recommended reading for such a situation is Working Effectively With Legacy Code by Michael Feathers.

In general, unit testing GUI elements is better avoided. So the most important thing is to try to separate logic to be tested from the GUI code, into POJOs which are easier to unit tests. Then start writing unit tests for the classes containing the logic, one by one... try to pick the most critical code parts first, to maximize your return of investment. Often a good way to achieve this is simply whenever you touch a class / method, write unit tests for it. This way you can gradually increase your code coverage.

Péter Török
A: 

I can't fully understand your question. A comprehensive testing strategy it's hard to plan carefully.

But if you have written carefylly your test cases with a unit-testing framework (i.e. JUnit), you can analyze your software using a code-coverage tool (i.e. Cobertura).

Eclipse has a good plugin for JUnit, and Cobertura can be easily integrated in your build project using Ant or Maven.

frm
Could you please direct me to some instructions how to integrate the plugin and Cobertura using Maven
Global Dictator
A: 

That question leave things wide open, what type of testing are you really wanting to do?

Unit testing implies checking your custom code at the method interface level, and the tool for that is JUnit.

However, you specifically mention that this is a Swing application, so are you looking for a way to automate the interactions with the GUI for testing/regression purposes? That is a horse of a different color. In this case, since you mentioned using eclipse, you might want to look at GUIdancer. You can also google for automated UI testing and see that there is a large selection of commercial products available, but there is not a general solution, each fits in its own environmental niche.

JiroDan
+3  A: 

IMO FEST is currently the best framework to accomplish that. Just write your JUnit tests using it. More info is at

http://fest.easytesting.org/swing/wiki/pmwiki.php

http://code.google.com/p/fest/

eugener