This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Anyone using Scala and ScalaTest with AWT or java.awt.Robot? I'd love to steal some code to get me started...

4 replies
Ken McDonald
Joined: 2011-02-13,
User offline. Last seen 42 years 45 weeks ago.
I'm getting into testing UIs for the first time, and if anyone has examples I can learn from, or higher-level libraries I can use, that'd be great
Thanks,Ken
Rick Mugridge
Joined: 2011-03-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Anyone using Scala and ScalaTest with AWT or java.awt.Robot
It's been awhile since I've done that, but...
Robot is rather low-level and there are other open-source tools that do a better job.
If I were to do such testing with Swing, I'd use WindowLicker: http://code.google.com/p/windowlicker/
This is discussed in "Growing OO Systems Guided by Tests", which is an excellent book. WindowLicker is developed by Nat Pryce, one of the authors, and others.
Cheers, Rick
On Fri, Apr 1, 2011 at 9:05 AM, Ken McDonald <ykkenmcd@gmail.com> wrote:
I'm getting into testing UIs for the first time, and if anyone has examples I can learn from, or higher-level libraries I can use, that'd be great
Thanks,Ken

Philippe Lhoste
Joined: 2010-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Anyone using Scala and ScalaTest with AWT or java.awt.Robot?

On 31/03/2011 22:05, Ken McDonald wrote:
> I'm getting into testing UIs for the first time, and if anyone has examples I can learn
> from, or higher-level libraries I can use, that'd be great

Fest is made for that...

Andreas Scheinert
Joined: 2011-02-11,
User offline. Last seen 42 years 45 weeks ago.
Re: Anyone using Scala and ScalaTest with AWT or java.awt.Robot?

Hi Ken!
I would also recommend you a swing UI test framework. This one:
http://www.uispec4j.org/
Here an example where my Swing App is a a Simple JFrame which contains
a Jcombobox, a JList and a button.
Finally it contains an ActionListener which takes the selected value
from the ComboBox and puts it into the List if the button is pressed.
Here is the code to verfiy that:

public class ParameterDetailTest extends UISpecTestCase {

public void testCreatingAContact() throws Exception {
Window window = getMainWindow();
//For now we use getMethods from the original JFrame class
MyJFrame pd = (MyJFrame) window.getAwtContainer();
//uispec4j uses wrappers for swing components
ListBox lb = new ListBox(pd.getJList()); // or new JList()

assertTrue(lb.isEmpty());

Button add = new Button(pd.getButton());

add.click();

ComboBox box=new ComboBox(pd.getCombo());

String[] someStrings=new String[]{”001″};

assertTrue(lb.contentEquals(someStrings));
}

protected void setUp() throws Exception {
setAdapter(new MainClassAdapter(MyJFrame.class, new String[0]));
}

}

hth andreas
On 31 Mrz., 22:05, Ken McDonald wrote:
> I'm getting into testing UIs for the first time, and if anyone has examples
> I can learn from, or higher-level libraries I can use, that'd be great
>
> Thanks,
> Ken

Philippe Lhoste
Joined: 2010-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Anyone using Scala and ScalaTest with AWT or java.awt.Robot?

> Fest is made for that...

Posted hastily, now at home I can give the link:
http://fest.easytesting.org/
As said, it is not the only Swing testing tool, I will look at the
others with interest.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland