Jump to content
  • Advertisement
Sign in to follow this  
Glass_Knife

Unit Test Java Swing

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have looked at various tools for testing swing code, but none of them are easy to use, and require tons of code to setup. Event for a small UI it is hard to keep the test code current. Does anyone use a good (free) Swing testing tool? I have many books on TDD, and most of them say "Don't test GUI code." Although most of the things I do do not require a UI to test them, some things are hard to test. Has anyone been successful with a UI that didn't need to be tested?

Share this post


Link to post
Share on other sites
Advertisement
yes, it's quite easy to build GUI's that do not require testing. Write all your "business logic" in a seperate class from the control frame. Test the business logic class, make the wired up connections to the front end for user input, and trust that clicking a button actually fires an event.

I find this especially true for Java, as I think code gets really cluttered when you put all your logic in with your GUI.

But sometimes, your tests take a lot of work. That doesn't mean they aren't worth doing.

Share this post


Link to post
Share on other sites
Quote:
Original post by capn_midnight
Write all your "business logic" in a seperate class from the control frame. Test the business logic class, make the wired up connections to the front end for user input, and trust that clicking a button actually fires an event.


I agree with this, and I try and do this as much as I can, but there are still things that the GUI needs to do that need to be tested. For instance, in one app, a file is sent to a server, and the progress is displayed on the GUI with a progress bar. There is lots of logic to handle the progress bar in the GUI code. Also, I have many places where depending on the state of the DataObject, controls are enabled/disabled. How can this stuff be tested without testing the GUI.

Share this post


Link to post
Share on other sites
Quote:
Original post by Glass_Knife
Quote:
Original post by capn_midnight
Write all your "business logic" in a seperate class from the control frame. Test the business logic class, make the wired up connections to the front end for user input, and trust that clicking a button actually fires an event.


I agree with this, and I try and do this as much as I can, but there are still things that the GUI needs to do that need to be tested. For instance, in one app, a file is sent to a server, and the progress is displayed on the GUI with a progress bar. There is lots of logic to handle the progress bar in the GUI code. Also, I have many places where depending on the state of the DataObject, controls are enabled/disabled. How can this stuff be tested without testing the GUI.


like I said, the actual operation of the GUI is not your code, you don't need to test it. Just trust it works. Make sure that you test for returning the states properly. Also, you can try mock objects for the GUI elements. They are objects that utilize your business logic in the same way in which a GUI would utilize it, but you have complete programmatic control over the objects. Interfacing will go a long way to help you with this.

If a certain set of conditions means "set control to disabled", then test those conditions. Don't worry about testing to see if setting the enabled property to false actually makes the control unusable: that is assumed.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!