Should I Test such Trivial Stuff?
I try to write my code test first nowadays. But of course it happens that I have to work with code that doesn’t have tests. Maybe I was undisciplined and skipped the tests, or somebody else wrote it, or what ever. When it is feasible I try to add test until I have 100% or close to 100% coverage. But sometimes I come across really trivial code. Like a simple two or three line method. Or a bunch of getters and setters. And then I ask my self.
“Should I test such trivial stuff?”
The answer IMHO is “YES!!”
The arguments are really simple:
- if it is trivial to write and understand it should be trivial to test. So we are not talking about hours of work here.
- If somebody is adding stuff to this code she might not realize it is not properly tested.
- And last but not least: over and over again I have written tests for trivial stuff just to see them turn red on me immediately. Bugs like to hide in trivial code, because nobody really looks at trivial code, and trivial code tends to get created via cut’n'paste which offers lot of opportunities for bugs.
So write a test for that little piece of code. If you have lots of pieces like it, consider to make a little test helper using reflection or a dynamic language. Make 100% your standard.






What kind of testing method do you use to test a Swing-GUI? Do you know a good tool or framework to create black-box tests for Swing applications?
I have used Abbot a long time ago. But I strongly recommend to build your app in a way, that you can test right below the GUI.
Everything else is lots of work for not much gain.
I would use Fest. It made the GUI testing I’ve done fairly easy. I’m in agreement on Jens though, with keeping the core of the code outside of the GUI so you can test it separately.
Thank you for your answers.
We have an application from a provider and extend the application with GUI plugins. I see no other way to test the integration of the plugins but to create GUI-tests. The core of our code is inside the model so we can test it with comparatively little effort.