Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking eclipse SWT/JFACE dialogs and widgets

Is there a way how to unit test eclipse dialogs and SWT/Jface widgets? Or even better - is there some jar/framework which can help me mock Shell or Composite (in that way so I wouldn't have to mock too many their methods) ?

like image 490
mawek Avatar asked Nov 04 '22 14:11

mawek


1 Answers

You are looking for a framework to mock the SWT controls. This is generally considered best practice when using TDD or when your tests must be reliable.

SWTBot does not mock SWT. When using SWTBot, the target code executes using the standard SWT implementation for the host OS. SWTBot inspects and triggers the SWT controls from another thread. This approach does not isolate the code from the environment and tests may give different results depending on the host platform and other environmental differences that affect SWT.

Unfortunately general purpose mock libraries such as Mockito or JMockit just can't be used to mock SWT due to a combination of a lack of injectable constructors, code that validates packages, hierarchies, and final classes and methods. For a library such as SWT you will need to use custom stubs. A search does not show any SWT mock libraries. I have therefore started one at https://github.com/westbury/SWT-Mock.

like image 108
Nigel W Avatar answered Nov 12 '22 17:11

Nigel W