Code Coverage

5 views
Skip to first unread message

Sachin

unread,
Jun 10, 2008, 12:56:42 AM6/10/08
to crosscheck
Hi,

We are using crosscheck for writing tests for webscripts (Alfresco
webscripts http://www.alfresco.com). Webscripts are server side
javascript files which will be invoked to perform some small
operation. We are really amazed by the simplicity of crosscheck. Now,
I want to build a code-coverage matrix for my tests (something like
http://cobertura.sourceforge.net/).

Have anybody done that already?

Thanks in advance.

Regards,

Sachin
http://www.thoughtworker.in

Charles Lowell

unread,
Jun 10, 2008, 12:27:49 PM6/10/08
to cross...@googlegroups.com
Sachin,

Glad you like crosscheck! Unfortunately there is no coverage tool that comes rolled with crosscheck, however, you can write one fairly quickly with the Rhino debugger API.

I was able to whip up this (admittedly lame) coverage tool in about 20 minutes. Obviously, it lacks all the features of a full coverage api (all it does is track line numbers, but the debugger api is quite powerful, and should be capable of everything you're wanting to do.

Note that to use the debugger api, you have to turn off all optimization, which could effect performance.

I've attached a copy of my quick example. Basically, it collects information about your sources, then when you are ready to start calling code, it turns off collection, and then as you make calls, it tracks which lines in which files/functions were called.

cheers,

calls.js
Coverage.java
source.js

Charles Lowell

unread,
Jun 10, 2008, 1:10:27 PM6/10/08
to cross...@googlegroups.com
For those of you who had the javascript attachments removed from the last email (like me) 

I'm including the sources inline. If you got the originals, nevermind.


Charles Lowell
The Frontside Software

source.js:


function willBeCalled() {
java.lang.System.out.println('I was called')
}

function willBeCalledAsWell() {
var aVar;
if (aVar) {
java.lang.System.out.println('will also never be called')
}
}

function willNotBeCalled() {
java.lang.System.out.println('I was called. wtf?')
}


calls.js:

willBeCalled();
willBeCalledAsWell();


Sachin Dharmapurikar

unread,
Jun 10, 2008, 1:56:37 PM6/10/08
to cross...@googlegroups.com
Thanks a ton Charles. I will look into this and see how I can put more chops in that :)

I wish, I could create an simple extension on a weekend and put together a good analyzer.

Regards,
Sachin

Charles Lowell

unread,
Jun 10, 2008, 5:36:40 PM6/10/08
to cross...@googlegroups.com
And one more thing. I forgot to include the program output:

>>>>>>>>>
source.js:2
source.js:3
I was called
source.js:6
source.js:8
called 4 out of 7 lines (57%)
>>>>>>>>>>

As I mentioned earlier, the debugger API gives you pretty much all the information you need to find out what function/script is being called, when, and how many times.


Charles Lowell
The Frontside Software



Reply all
Reply to author
Forward
0 new messages