Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

JUnit testing

Richard Schmidt
1 decade ago Apr 07, 2010 1:44am

Hi

Has anyone go any ideas how best to test a Vaadin application?

I guess you could use Selenium but you would end up with slow application tests that are very fragile.

I would like to write a JUnit test typically would check that (say) pressing button X results in a particular lump of code being called.

I have been considering using the "humble view" pattern proposed by Martin Fowler. I suspect it would work rather well as Vaadin components implements lots of interfaces. Has anyone explored this option.

link to fowler's humble View article

Thanks
Richard

Last updated on Apr, 7th 2010
Jonas Granvik
1 decade ago Apr 07, 2010 7:53am
Joonas Lehtinen
1 decade ago Apr 07, 2010 11:53am

Jonas Granvik: Testbench is a adopted version of Selenium to better fit Vaadin's requirements. http://vaadin.com/testbench

Just to follow up - TestBench will be added to Vaadin Directory shortly with 1199 USD / developer license price tag. If you do not want to wait, please contact sales - they will provide you with a beta copy of the upcoming version (that you can try out free for 30 days) and could even give a discount if your development team is larger than a handful of developers.

With TestBench you can package any screen recorded tests as JUnit tests and run them from your continuous integration server. In addition to DOM-based assertions - you can also do pixel level comparisons to detect visual regressions in your theme with a number of web browsers. Vaadin Framework itself uses such testing extensively with hundreds of pixel-level tests run for each Vaadin Framework build.

Last updated on Apr, 7th 2010
Richard Schmidt
1 decade ago Apr 13, 2010 9:54pm

Jonas Granvik: Testbench is a adopted version of Selenium to better fit Vaadin's requirements. http://vaadin.com/testbench

Just as a short note. I'll leave the jUnit thinkering to someone better suited to answer that.

It is good to know that one can write application tests using selenium, but I am more concerned about unit testing of my code - I would leave the testing of Vaadin code to you guys
-_-

Taking the a simple example of a button click changing the text on a label. I would like to write a unit code that does something like the following

button.fireClickEvent();
assertEquals( "new Message", label.getValue());

Not that I am not trying to test that the label actually works by updating the users browser, but only that my code called the setValue() method in the label.

I guess I could mock the label using Mockito an do something like

button.fireClickEvent();
verify( label).setValue());

but there is no easy way of mocking the firing of the button click event.

I have written one or two very small simple tests and it looks as if it is possible, I would just like to ask if anyone else has been down this path?

Joonas Lehtinen
1 decade ago Apr 14, 2010 6:51am

The correct method to call is button.fireClick(). The problem is that the event is protected. Created a ticket for it: http://dev.vaadin.com/ticket/4530.

Before this is resolved, you can call button.handleAction(null,null). It should do the exactly same thing, but sounds unintuitive.

Tim Schraepen
1 decade ago Jul 21, 2011 11:53am
Stéphane Nicoll
10 years ago Dec 18, 2011 5:50am
Joonas Lehtinen
10 years ago Dec 18, 2011 7:14am
Stéphane Nicoll
10 years ago Dec 18, 2011 7:30pm
Stéphane Nicoll
10 years ago Dec 22, 2011 6:29pm
Stéphane Nicoll
10 years ago Jan 10, 2012 7:06pm
Artur Signell
10 years ago Feb 10, 2012 8:44am
Thomas Santana
10 years ago Apr 09, 2012 1:12am
Joachim Dietl
4 years ago Oct 04, 2017 7:58am
Martin Vyšný
2 years ago Apr 28, 2019 5:55pm