Page 1 of 2

Java script code coverage

Posted: 2009-02-26 1:54 pm
by Saran
Hi,

We are having a requirement to generate the coverage report for a set of java script files, and store the coverage report programmatically in a html file.

Now, I am through in running the jsunit test cases with testRunner.html. How to proceed further using JSCoverage to create the coverage report.

Thanks,
Saran

Re: Java script code coverage

Posted: 2009-02-26 2:53 pm
by Ed
To store a coverage report you will need to use the jscoverage-server program. Are you using jscoverage-server?

Re: Java script code coverage

Posted: 2009-02-26 3:31 pm
by Guest
Ed wrote:To store a coverage report you will need to use the jscoverage-server program. Are you using jscoverage-server?
Thanks for your quick reply.

No, I am not using the jscoverage-server program.

Currently the Tomcat web server is started from the ant build file to execute the jsunit test cases. Please tell us how to start the jscoverage-server from build file.

Thanks,

Re: Java script code coverage

Posted: 2009-02-26 3:43 pm
by Ed
If your test suite requires the Tomcat server (presumably you are using servlets/JSPs in your project), then you will probably want to run jscoverage-server with the --proxy option. See the manual for details on the jscoverage-server command-line options.

Re: Java script code coverage

Posted: 2009-02-27 9:12 am
by saran
Hi,

I started the jscoverage-server with --proxy option, and executed the test cases from a test suite using JSunit. The following code snippet is included in the test suite.

function tearDownPage() {
if (window.jscoverage_report) {
jscoverage_report();
}
}

But the coverage report is not generated after executing all the test cases.

The steps which I followed are

1. Started the tomacat web server from the build file.
2. Started the jscoverage-server from the build file.
<exec executable="${lib.dir}/jscoverage-0.4/jscoverage-server.exe" spawn="true">
<arg value="--verbose" />
<arg value="--port=8888" />
</exec>
3. executed the test cases through testrunner.html using the URL "http://localhost:8080/testrunner.html?t ... suite.html"
3. Stopped the jscoverage-server.
4. Stopped the tomcat server.

After performing all these steps the coverage report is not generated. Please let me know if I am wrong anywhere.

Thanks,

Re: Java script code coverage

Posted: 2009-02-27 3:01 pm
by Ed
saran wrote:2. Started the jscoverage-server from the build file.
<exec executable="${lib.dir}/jscoverage-0.4/jscoverage-server.exe" spawn="true">
<arg value="--verbose" />
<arg value="--port=8888" />
</exec>
3. executed the test cases through testrunner.html using the URL "http://localhost:8080/testrunner.html?t ... suite.html"
This looks a little strange ... are you using the --proxy option?

Re: Java script code coverage

Posted: 2009-02-27 4:32 pm
by Guest
Yes, it is a copy paste mistake. Here is the correct code in the build file.

<echo message="Starting jscoverage server....."/>
<exec executable="${lib.dir}/jscoverage-0.4/jscoverage-server.exe" spawn="true">
<arg value="--verbose" />
<arg value="--proxy" />
<arg value="--port=8888" />
</exec>

Please let me know where I am going wrong.

Re: Java script code coverage

Posted: 2009-02-27 6:15 pm
by Ed
Okay, I think the command-line options are all right ...
  • Is your web browser set up to use the proxy?
  • Is the tearDownPage function getting executed? (This requires JSUnit version 2.2.)
  • Are there any errors (e.g., in the web browser's error console)?
Using code like this might help:

Code: Select all

function tearDownPage() {
  alert('tearDownPage');
  if (window.jscoverage_report) {
    alert('jscoverage_report exists');
    jscoverage_report();
    alert('jscoverage_report executed');
  }
}

Re: Java script code coverage

Posted: 2009-03-02 6:38 am
by Guest
Ed wrote:
  • Is your web browser set up to use the proxy?
Yes, Browser setup is done to use the proxy. IP:127.0.0.1 Port:8888
Ed wrote:
  • Is the tearDownPage function getting executed? (This requires JSUnit version 2.2.)
The function is not getting executed. Using JSUnit version 2.2. The provided function is included after the function which executes all the test cases inside the test suite file. There was no alert message after executing the test cases.
Ed wrote:
  • Are there any errors (e.g., in the web browser's error console)?
[/list]
There is no error in the error console of the web browser.

Note: I am not instrumenting the js file as,I hope there is no need for instrumentation while running the jscoverage-server.

Re: Java script code coverage

Posted: 2009-03-02 4:55 pm
by Ed
Are you able to run the example that comes with JSCoverage? Copy the contents of the doc/example-jsunit/ directory into your web server's document root, edit test.html to add an alert() statement to the top of the tearDownPage() function, then visit the URL:

Code: Select all

http://127.0.0.1:8080/jsunit/testRunner.html?testPage=http://127.0.0.1:8080/test.html&autoRun=true
Does the tearDownPage function get called?

Re: Java script code coverage

Posted: 2009-03-02 5:19 pm
by Guest
Hi,

I copied the example as you told and accessed the URL.

Code: Select all

function tearDownPage() {
alert(window.jscoverage_report);
  if (window.jscoverage_report) {
  alert("Hi");
    jscoverage_report();
  }
}
The function is getting executed and the value for "window.jscoverage_report" shown as "undefined", and the second alert is not displayed.

Re: Java script code coverage

Posted: 2009-03-02 5:38 pm
by Ed
Basically, the example test suite is designed to work with or without the jscoverage-server proxy running. Without the proxy, jscoverage_report will be undefined. With the proxy, jscoverage_report should be defined as a function, and then the function will be called. Are you running the example test suite through the proxy?

Re: Java script code coverage

Posted: 2009-03-02 5:44 pm
by Guest
No, I am not running the test suite through the proxy.

Re: Java script code coverage

Posted: 2009-03-02 5:49 pm
by Guest
When I run the test suite after starting the jscoverage-server proxy also I got the same undefined value and the coverage is not generated.

Re: Java script code coverage

Posted: 2009-03-02 5:51 pm
by Ed
If you run the example through the proxy, it should create a "jscoverage-report/", directory containing the stored coverage report. (This will be located in the directory where you started the jscoverage-server program.) Does that work correctly?