Java script code coverage

Questions, problems, suggestions, bug reports, and so on.
Saran

Java script code coverage

Post by Saran » 2009-02-26 1:54 pm

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

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: Java script code coverage

Post by Ed » 2009-02-26 2:53 pm

To store a coverage report you will need to use the jscoverage-server program. Are you using jscoverage-server?

Guest

Re: Java script code coverage

Post by Guest » 2009-02-26 3:31 pm

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,

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: Java script code coverage

Post by Ed » 2009-02-26 3:43 pm

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.

saran

Re: Java script code coverage

Post by saran » 2009-02-27 9:12 am

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,

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: Java script code coverage

Post by Ed » 2009-02-27 3:01 pm

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?

Guest

Re: Java script code coverage

Post by Guest » 2009-02-27 4:32 pm

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.

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: Java script code coverage

Post by Ed » 2009-02-27 6:15 pm

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');
  }
}

Guest

Re: Java script code coverage

Post by Guest » 2009-03-02 6:38 am

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.

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: Java script code coverage

Post by Ed » 2009-03-02 4:55 pm

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?

Guest

Re: Java script code coverage

Post by Guest » 2009-03-02 5:19 pm

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.

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: Java script code coverage

Post by Ed » 2009-03-02 5:38 pm

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?

Guest

Re: Java script code coverage

Post by Guest » 2009-03-02 5:44 pm

No, I am not running the test suite through the proxy.

Guest

Re: Java script code coverage

Post by Guest » 2009-03-02 5:49 pm

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.

Ed
Posts: 120
Joined: 2008-10-11 6:52 pm

Re: Java script code coverage

Post by Ed » 2009-03-02 5:51 pm

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?

Post Reply