Home » Eclipse Projects » Remote Application Platform (RAP) » RAP/RWT JUnit testing
RAP/RWT JUnit testing [message #935009] |
Sat, 06 October 2012 15:15 |
Mariusz Cwikla Messages: 15 Registered: January 2012 |
Junior Member |
|
|
Hello,
is it possible to create unit tests for RAP without opening browser? I tried to use RAPTestCase, but what I see is that it creates workbench and opens web browser.
Instead, what I need is to perform some simple user interface logic tests. For example, I have some simple composite, let's say:
public class MyComposite extends Composite {
private Text text;
private Button checkbox;
public MyComposite(Composite parent, int style) {
super(parent, style);
checkbox = new Button(this, SWT.CHECK);
checkbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
text.setEnabled(checkbox.isEnabled());
}
});
checkbox.setText("checkbox");
text = new Text(this, SWT.BORDER);
text.setBounds(41, 92, 76, 21);
}
public Button getCheckbox() {
return checkbox;
}
public Text getText() {
return text;
}
}
It's very simple example, that shows that text is enabled when checkbox is checked. In real world I would have more complicated composites, for example - a button that calls some services, and renders data in table, etc. I'd like to test that more complicated cases.
Anyway, I would like to create a test like this:
class MyTest extends RAPTestCase{
Display display ;
Shell shell;
@Override
protected void setUp() throws Exception {
display = Display.getCurrent();
shell = new Shell(display, SWT.NONE);
}
public void testMyComposite(){
MyComposite c = new MyComposite(shell, SWT.NONE);
c.getCheckbox().setSelection(true);
assertTrue(c.getText().isEnabled());
}
}
When I run it as a RAPTestCase it creates Workbench and opens browser. When I run it as a JUnit Plug-in Test case I get problems with getting Display and Shell objects.
When I create Display with new operator:
@Override
protected void setUp() throws Exception {
display = new Display();
shell = new Shell(display, SWT.NONE);
}
then I get:
java.lang.IllegalStateException: No context available outside of the request service lifecycle.
at org.eclipse.rwt.internal.service.ContextProvider.getContext(ContextProvider.java:105)
at org.eclipse.rwt.internal.service.ContextProvider.getRequest(ContextProvider.java:116)
When I create a shell with empty constructor without creating a display:
protected void setUp() throws Exception {
shell = new Shell();
}
then I get:
java.lang.NullPointerException
at org.eclipse.swt.widgets.Widget.isValidThread(Widget.java:918)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:901)
I even tried to use Fixture class from org.eclipse.rap.rwt.testfixture, but I get:
java.lang.IllegalAccessError: tried to access field org.eclipse.rwt.internal.application.ApplicationContext.skipResoureRegistration from class org.eclipse.rwt.internal.application.ApplicationContextHelper
|
|
|
Re: RAP/RWT JUnit testing [message #936616 is a reply to message #935009] |
Mon, 08 October 2012 06:40 |
Ivan Furnadjiev Messages: 2429 Registered: July 2009 Location: Sofia, Bulgaria |
Senior Member |
|
|
Hi,
yes... it's possible the create plain JUnit tests without problem. You
have to call some Fixture methods in setUp and tearDown to initialize
the environment like:
public class MyTest extends TestCase {
private Display display;
private Shell shell;
@Override
protected void setUp() throws Exception {
Fixture.setUp();
Fixture.fakePhase( PhaseId.PROCESS_ACTION );
display = new Display();
shell = new Shell( display );
}
@Override
protected void tearDown() throws Exception {
Fixture.tearDown();
}
public void testMyComposite() {
....
}
HTH,
Ivan
On 10/6/2012 6:15 PM, Mariusz Cwikla wrote:
> Hello,
> is it possible to create unit tests for RAP without opening browser? I
> tried to use RAPTestCase, but what I see is that it creates workbench
> and opens web browser.
>
> Instead, what I need is to perform some simple user interface logic
> tests. For example, I have some simple composite, let's say:
>
>
> public class MyComposite extends Composite {
> private Text text;
> private Button checkbox;
>
> public MyComposite(Composite parent, int style) {
> super(parent, style);
>
> checkbox = new Button(this, SWT.CHECK);
> checkbox.addSelectionListener(new SelectionAdapter() {
> @Override
> public void widgetSelected(SelectionEvent e) {
> text.setEnabled(checkbox.isEnabled());
> }
> });
> checkbox.setText("checkbox");
>
> text = new Text(this, SWT.BORDER);
> text.setBounds(41, 92, 76, 21);
>
> }
>
> public Button getCheckbox() {
> return checkbox;
> }
> public Text getText() {
> return text;
> }
> }
>
>
> It's very simple example, that shows that text is enabled when
> checkbox is checked. In real world I would have more complicated
> composites, for example - a button that calls some services, and
> renders data in table, etc. I'd like to test that more complicated cases.
>
> Anyway, I would like to create a test like this:
>
> class MyTest extends RAPTestCase{
> Display display ;
> Shell shell;
>
> @Override
> protected void setUp() throws Exception {
> display = Display.getCurrent();
> shell = new Shell(display, SWT.NONE);
> }
>
> public void testMyComposite(){
> MyComposite c = new MyComposite(shell, SWT.NONE);
> c.getCheckbox().setSelection(true);
> assertTrue(c.getText().isEnabled());
> }
> }
>
> When I run it as a RAPTestCase it creates Workbench and opens browser.
> When I run it as a JUnit Plug-in Test case I get problems with getting
> Display and Shell objects.
> When I create Display with new operator:
>
> @Override
> protected void setUp() throws Exception {
> display = new Display();
> shell = new Shell(display, SWT.NONE);
> }
>
> then I get:
>
> java.lang.IllegalStateException: No context available outside of the
> request service lifecycle.
> at
> org.eclipse.rwt.internal.service.ContextProvider.getContext(ContextProvider.java:105)
> at
> org.eclipse.rwt.internal.service.ContextProvider.getRequest(ContextProvider.java:116)
>
> When I create a shell with empty constructor without creating a display:
>
> protected void setUp() throws Exception {
> shell = new Shell();
> }
>
> then I get:
>
> java.lang.NullPointerException
> at org.eclipse.swt.widgets.Widget.isValidThread(Widget.java:918)
> at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:901)
>
>
> I even tried to use Fixture class from
> org.eclipse.rap.rwt.testfixture, but I get:
> java.lang.IllegalAccessError: tried to access field
> org.eclipse.rwt.internal.application.ApplicationContext.skipResoureRegistration
> from class org.eclipse.rwt.internal.application.ApplicationContextHelper
>
--
Ivan Furnadjiev
Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/
Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
|
|
| | | | | |
Goto Forum:
Current Time: Sun Jan 26 09:47:46 GMT 2025
Powered by FUDForum. Page generated in 0.03206 seconds
|