After my little blog series about Jubula, I thought I’d try out something similar using SWTBot. However, there’s no use in writing the same tutorial again for the RCP mail application because it’s already there…
Nevertheless, I attempted to implement the same few tests I wrote for Jubula, and you can view the results in the piece of code below:
It’s a set of three tests opening the “Open Message” dialog via toolbar button, keyboard shortcut or menu entry. Simple.
At first glance, this looks neat, especially if you’re a developer: few lines of code, all directly in Java, using the already familiar JUnit framework, well supported from within the Eclipse IDE.
Nevertheless, here’s my list of things I don’t like about this:
- Let's begin with a minor nitpick: I'm using a German keyboard layout, and SWTBot complains that it can't find my layout. This means that I either have to somehow create one (which might be easy, I haven't checked), or I have to set my keyboard layout to the US one (it doesn't matter for my simple
- Next, I can't write these tests in Scala for some reason (I'd really like to use Scala for my tests, so very much more concise): In Scala, the following line:
fails with a compile error in Eclipse: "Access to protected method
clicknot permitted because enclosing class object
ScalaUseris not a subclass of class
widgetswhere target is defined". - What's that? If you ask me, it's somehow caused by the
SWTBotToolbarButtonhaving an abstract public method
SWTBotToolbarButton, and inheriting from
AbstractSWTBot<T>, which has an abstract protected method
- Also, I don't want to use JUnit for system tests. JUnit is a great framework if all you do is unit tests. If you're testing on the level of integration or system tests, however, TestNG is a way better fit if you ask me. The execution model of TestNG is a lot more flexible than that of JUnit (even if you use decorators and stuff there). For example, have a look at the data providers of TestNG. Unfortunately, there's no TestNG integration for SWTBot.
- Finally, here's what I'd call a showstopper. Have you noticed how I say
toolbarButton(1)in my code instead of the
toolbarButtonWithTooltip("Open Message")you'd probably expect? That's because using the latter method will require another dependency in your plug-in project. That dependency will have to get injected into your test object, too (the RCP mail application in my case). And unfortunately, it will add toolbar buttons and keyboard shortcuts to your test object! In my case, this leads to
Ctrl-3suddenly not working as expected anymore: The tests have changed the behaviour of the test object! I absolutely can't have that happening.
For me, these four reasons unfortunately mean that SWTBot is not a viable tool for automating UI tests. I would really like to use it, especially combined with Scala, for quick and easy developer UI testing; I’d be quite happy if you could refute any of my four reasons above.
I’ve still got hope that maybe I’m just too stupid to use SWTBot correctly.