Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test Driven Development, Unit Testing

let me first explain what I'm aiming for with this question:

What kind of dev I am? I'm the guy who thinks about the problem, writes the code and then tests it by myself. I'm developing web-apps mainly but there are also projects which are UI based too (RCP/Swing apps). I run my app and click here, test this... You probably know this "style".

Well I'm a guy who tries to improve himself with every line/project and I want my code/apps to be tested pragmatically. I write in code - I want test in code.

So I started for some of my classes/functions to use unit tests (junit 4). This works for backend stuff where no UI is involved - tbh: I find it hard to write the most of tests. If we're building a webapp there are probably interactions with the session or something. I guess you get the point.

What I'm looking for are some resources probably with examples. Any good book advice would be welcome too. Don't get me wrong - I don't want only stuff for logic testing, I'm interested in ways to test my UI.

Maybe this is an important part too: I developing in Java (85% of the time) and PHP/Python (the rest)

Regards

like image 481
onigunn Avatar asked Jan 14 '11 22:01

onigunn


3 Answers

You can use to Selenium for complete front end testing under any mainstream testing framework (eg: JUnit). Then stick to just using a JVM alone for back end code, which is easy enough. You should be covered in this regard. With Selenium you are writing an end-to-end test as opposed to an atomic unit test on each aspect. That is a trade off to using the complete front end to test in.

like image 196
Zombies Avatar answered Sep 30 '22 15:09

Zombies


I find the technique described in The Humble Dialog Box very effective in test-driving my GUIs. Essentially, each GUI class is broken up into 3 classes and an interface: (1) the logic controller, which defines how the logic of the GUI behaves (changing labels, are things enabled? etc) fully testable and has no dependencies on the actual GUI, but does depend on (2) the view interface, which defines how the logic controller will interact with the GUI later. (3) The actual GUI class, which is a very thin wrapper to the real GUI library. Finally, (4) the fake view, which you use for testing to prove that your logic controller will manipulate the GUI correctly.

It may seem like a lot of work at first, but I encourage you to try it. I have had very few problems with my GUIs since I started doing this. The up-front work saves major headaches (and time) later.

like image 27
Daniel Gallagher Avatar answered Sep 30 '22 14:09

Daniel Gallagher


There are several frameworks that allows you to test your User Interface, i have been testing the UI with the FEST framework for my Swing UI. But there are other tools best suited to web application. Java Source has a great list of Open Source Web Testing Tools in Java.

like image 41
jhurtado Avatar answered Sep 30 '22 15:09

jhurtado