Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » RAP/RWT JUnit testing
RAP/RWT JUnit testing [message #935009] Sat, 06 October 2012 11:15 Go to next message
Eclipse UserFriend
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 02:40 Go to previous messageGo to next message
Eclipse UserFriend
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/
Re: RAP/RWT JUnit testing [message #972247 is a reply to message #936616] Mon, 05 November 2012 08:21 Go to previous messageGo to next message
Eclipse UserFriend
When I try this I get the following exception:

java.lang.IllegalAccessError: tried to access field org.eclipse.rap.rwt.internal.application.ApplicationContextActivator.skipResoureRegistration from class org.eclipse.rap.rwt.internal.application.ApplicationContextHelper
	at org.eclipse.rap.rwt.internal.application.ApplicationContextHelper.setSkipResoureRegistration(ApplicationContextHelper.java:20)
	at org.eclipse.rap.rwt.testfixture.Fixture.setSkipResourceRegistration(Fixture.java:490)
	at org.eclipse.rap.rwt.testfixture.Fixture.<clinit>(Fixture.java:101)
	at com.agetor.server.filters.tests.FilterReaderTest.before(FilterReaderTest.java:33)
	...

To me it looks like the bundle org.eclipse.rap.rwt.testfixture tries to access a field of a class (in the same package) from the bundle org.eclipse.rap.rwt - and thus another ClassLoader.

Any advice or any examples of proper use?
Should org.eclipse.rap.rwt.testfixture be a fragment on org.eclipse.rap.rwt?

My test class is based on JUnit 4 as follows:

public class FilterReaderTest {

	...
	private Display display;

	@Before
	public void before() {
		...

		Fixture.setUp();
		display = new Display();
	}

	@After
	public void after() {
		Fixture.tearDown();
	}

	/**
	 * Tests for the first filter...
	 */
	@Test
	public void testFilter1() {
		...
	}
}
Re: RAP/RWT JUnit testing [message #973687 is a reply to message #935009] Tue, 06 November 2012 09:41 Go to previous messageGo to next message
Eclipse UserFriend
Hello Tony,
I also thought that org.eclipse.rap.rwt.testfixture should be fragment in order for custom tests to work.

Ivan, are we right?
Re: RAP/RWT JUnit testing [message #973788 is a reply to message #973687] Tue, 06 November 2012 11:12 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
the mentioned issue has been fixed. See:
391510: IllegalAccessError when using Fixture
https://bugs.eclipse.org/bugs/show_bug.cgi?id=391510
Best,
Ivan

On 11/6/2012 4:41 PM, Mariusz Cwikla wrote:
> Hello Tony, I also thought that org.eclipse.rap.rwt.testfixture should
> be fragment in order for custom tests to work.
>
> Ivan, are we right?

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: RAP/RWT JUnit testing [message #974099 is a reply to message #973788] Tue, 06 November 2012 16:29 Go to previous messageGo to next message
Eclipse UserFriend
Ivan,

Do you have a working example where Fixture have been used in an OSGi application (with RAP) to test creation of images or similar?
Re: RAP/RWT JUnit testing [message #984067 is a reply to message #974099] Wed, 14 November 2012 06:16 Go to previous message
Eclipse UserFriend
Hi Tonny,

We use plain JUnit for all our tests to make them run fast. But we're
considering running them as OSGi tests on the build server. I've just
ran our ClientScripting tests [1] as PDE tests without problems.

But there were some recent fixes [2] that are not contained in M2, but
will be in M3 (published this Friday).

Regards, Ralf


[1]
http://git.eclipse.org/c/rap/incubator/org.eclipse.rap.incubator.clientscripting.git/tree/tests/org.eclipse.rap.clientscripting.test

[2] Bug 391510: IllegalAccessError when using Fixture
https://bugs.eclipse.org/bugs/show_bug.cgi?id=391510

--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Previous Topic:any doc or help for creating native custom widget with rap 2.0?
Next Topic:Upload file code deprecation
Goto Forum:
  


Current Time: Tue Jul 15 21:41:30 EDT 2025

Powered by FUDForum. Page generated in 1.37463 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top