Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Unit testing vaadin application
I am migrating a fairly complex vaadin application from 6 to 7. I need to unit-test the presentation layer logic: initial configuration of session variables, and then the behavior of my presentation layer instances. All that is java server-side code and the logic I want to test is quite distinct from visual aspect (which involves css, browser behavior, etc). So TestBench, which I have tried extensively, is not an answer.
In my vaadin 6 application I used ServletUnit http://httpunit.sourceforge.net/doc/servletunit-intro.html, which allowed me to unit test properly. However I can't seem to make it work with vaadin 7.3.1, even though I can start the application manually in a browser.
When I run a test, my servlet's init() and servletInitialized() methods are called, my class defined as a SessionInitListener has its sessionInit() method called (and it sets variables on the VaadinSession), however thereafter VaadinSession.getCurrent() returns null.
Any clues on where/how to locate the error? Thank you!
that is correct: vaadin ui and session is only constructed by vaadin servlet when there is an actual request. you could call the servlet with a mocked request, but there's an easier way to do it: the karibu-testing library which will set up everything for you: https://github.com/mvysny/karibu-testing please see the link for concrete examples and tutorial. Note that karibu-testing only support Vaadin 8 and above, so you need to migrate your app first.