1

I have an application and connect database with a gateway module. And I write gui tests and I start to use mockito. I try to update an object with open gui. I set combobox, textfield parameters and change them new parameters too but then call save method. My problem starts with save method.

I load my controller with

Platform.runlater(() -> {
  spyUpdate.loadItems(object1, object2);
});

I change object parameters and click to save button with

Button saveButton = find("#saveButton");
click(saveButton);

it calls save method. But this method goes to db so I write

Mockito.doNothing().when(spyUpdate).saveObjectToDb();

but this is not working? SaveObjectToDb function is called. Is there any idea. Using TestFX and Mockito how can I test my gui?

UPDATED:

//Button saveButton = find("#saveButton");
//click(saveButton);

  Mockito.doAnswer(new Answer() {
    @Override
    public Object answer(InvocationOnMock invocationOnMock) throws Throwable{
         Platform.runLater(() ->){
             AlertManager.setSUCCESS();
         });
        return null;
   }).when(spyUpdate).saveObjectToDb();

spyUpdate.saveObjectToDb();
  • or I change my question like how can I test my gui without use database objects. I want to create objects and use them at testfx. – user8945079 Nov 15 '17 at 13:42
  • Please, provide a code how do you initialize `spyUpdate` in production and test classes. Seems you have different instances and the mocking doesn't take effect. – Dmytro Maslenko Dec 10 '17 at 06:45

0 Answers0