GWTTestCase and Code Coverage Tools

132 views
Skip to first unread message

Ric Parks

unread,
Sep 5, 2006, 4:37:24 PM9/5/06
to Google Web Toolkit
My team is using the Coberatura code coverage tool to monitor the
percentage of code lines executed by our unit tests. The unit tests
that inherit from GWTTestCase don't report report coverage metrics and
I don't understand why. I'm hoping that someone out there can point me
in the right direction.

Coberatura works as follows: class files are instrumented/injected
with bytecode that writes out coverage information to a data file as
the code under test is executed by the unit test. Because hosted mode
actually loads the class bytecode into a JVM, it seems to me that the
metrics should still be written without a problem.

I think my question actually boils down to this: Does hosted mode go
back to the source file to create new bytecode when unit test are run?
Does hosted mode use the class files created during compilation for
unit tests?

Thanks,

Ric

VivekPrahlad

unread,
Sep 5, 2006, 11:45:43 PM9/5/06
to Google Web Toolkit
Ric,

The way the GWT works, your Java code is always compiled to JavaScript.
In essence, your GWT test cases end up running as javascript, not java.
Java bytecode never comes into the picture.

Unfortunately, this means that code coverage tools like Cobertura will
not work, as these tools work by instrumenting class files, as you're
rightly mentioned.

The only way I can see this working at the moment is if the GWT team
adds specific support for code coverage tools.

Hope this helps,
Vivek

Ric Parks

unread,
Sep 6, 2006, 1:14:39 PM9/6/06
to Google Web Toolkit
> The way the GWT works, your Java code is always compiled to JavaScript.

Is this true? The documentation says:

"By default, [unit] tests run in hosted mode as normal Java bytecode in
a JVM. "
and
"hosted mode, which means that you are interacting with your GWT
application without it having been translated into JavaScript."

Unless I'm completely misreading it, this seems to say pretty clearly
that unit tests are run in hosted mode and hosted mode does not compile
to JavaScript.

ijuma

unread,
Sep 6, 2006, 9:00:41 PM9/6/06
to Google Web Toolkit
Yes, that is my understanding as well. It would be interesting to hear
a reply from the GWT team explaining the problem.

Miguel Méndez

unread,
Sep 11, 2006, 3:57:40 PM9/11/06
to Google-We...@googlegroups.com
Hello Ric,

I will try to explain what you are seeing.  The JUnit hosted mode code is always executed as Java code.  The JUnit web mode code is always run as javascript.  However, because your TestCase instance could have JSNI code in it, we "recompile" it  from source.  This recompilation produces new bytecode that has had the JSNI references patched up.  It is the new version of the bytecode that we execute and not your instrumented version.  That is why you do not get coverage information.

It would require some work on our part to support code coverage tools etc.

I hope that helps,


On 9/6/06, ijuma < ism...@gmail.com> wrote:

Yes, that is my understanding as well. It would be interesting to hear
a reply from the GWT team explaining the problem.







--
Miguel

Ric Parks

unread,
Sep 12, 2006, 1:09:06 PM9/12/06
to Google Web Toolkit
Thanks Miguel. Very helpful response. I'll check out the Emma
coverage tool to see if that helps. It can instrument on the fly using
an instrumenting classloader. Has anyone had experience using Emma
with GWT?

Miguel Méndez

unread,
Sep 12, 2006, 2:56:11 PM9/12/06
to Google-We...@googlegroups.com
Hello Ric,

I wanted to let you know that we have our own classloader that we use in hosted mode JUnit.  So, you would need to give our class loader a chance to do its thing and then your instrumenting class loader could take over from there.
--
Miguel
Reply all
Reply to author
Forward
0 new messages