I am unit testing my application with JUnit. It uses (or tries to use...) the MVP pattern, hibernate and a swing gui.
In my test, I am testing whether persistence works as expected, e.g. is the date format correct, are the relationships between the database tables correct, etc.
Here's an (edited) example:
@Test
public void testCheckBeitragCalculation() {
MainView view = new MainView();
view.initGUI();
Controller persist = new Controller(view);
persist .saveData(testObject);
Controller edit = new Controller(view);
Controller search = new Controller(edit);
search.getData("10001"); // primary key
TestObject t2 = edit.getViewData();
assertEquals(10, t2.getBeitrag());
}
I initiate the main view because two controllers needs a reference to the main view to pass data.
Controller persist persists the object, Controller edit is the controller for the editing view and Controller search needs a reference to edit because it looks up an entity in the database and then displays this data in the editing view through the edit controller.
Because these controllers display the data in the GUI, the GUI shows up a split second during the unit test.
Is that bad practice? I've read that you shouldn't test GUI code, but I'm not testing the GUI itself, it just gets called by the tested code.
Thanks for advice!
Aucun commentaire:
Enregistrer un commentaire