How to unit test JsInterop code

176 views
Skip to first unread message

Paul Stockley

unread,
May 1, 2016, 11:00:09 AM5/1/16
to GWT Contributors
What is the best way to unit test JsInterop code? Am I correct that GWTTestCase doesn't work?

Jens

unread,
May 1, 2016, 11:46:26 AM5/1/16
to GWT Contributors
Depending on what exactly you want to test I would try hard using plain JUnit with mocking / stubbing. Testing @JsType(native = true) annotated interfaces / classes probably does not make a lot of sense given that the underlying JS code should already be tested and given that GWT itself has tests to ensure that JsInterop works correctly. 

But in general GWTTestCase should just work with JsInterop because they should be executed in web-mode by default now.

-- J.

Thomas Broyer

unread,
May 1, 2016, 12:55:24 PM5/1/16
to GWT Contributors


On Sunday, May 1, 2016 at 5:46:26 PM UTC+2, Jens wrote:
Depending on what exactly you want to test I would try hard using plain JUnit with mocking / stubbing. Testing @JsType(native = true) annotated interfaces / classes probably does not make a lot of sense given that the underlying JS code should already be tested and given that GWT itself has tests to ensure that JsInterop works correctly. 

But in general GWTTestCase should just work with JsInterop because they should be executed in web-mode by default now.

I think you *have* to run them in prod mode though (this is now the default, but in case your gwt.args contains an explicit -devMode, you may want to remove it or replace it with -web or -prod) 

Goktug Gokdogan

unread,
May 2, 2016, 2:06:23 PM5/2/16
to google-web-toolkit-contributors
A powerful mocking tool. like PowerMock, will let you mock native JsType if you prefer pure JRE unit tests.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/73974bec-3e59-4b92-8553-004b29069624%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Paul Stockley

unread,
May 2, 2016, 2:59:09 PM5/2/16
to GWT Contributors
I was looking more to do some basic sanity tests of JsInterop interfaces against actual Javascript libraries (to detect changes in API etc). I hadn't looked at GWTTestCase for a while but remembered it ran DevMode. Looks like I will be able to use webMode.
Reply all
Reply to author
Forward
0 new messages