Java script code coverage
Java script code coverage
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
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
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: Java script code coverage
To store a coverage report you will need to use the jscoverage-server program. Are you using jscoverage-server?
Re: Java script code coverage
Thanks for your quick reply.Ed wrote:To store a coverage report you will need to use the jscoverage-server program. Are you using jscoverage-server?
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,
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: Java script code coverage
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
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,
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,
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: Java script code coverage
This looks a little strange ... are you using the --proxy option?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"
Re: Java script code coverage
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.
<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.
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: Java script code coverage
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)?
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
Yes, Browser setup is done to use the proxy. IP:127.0.0.1 Port:8888Ed wrote:
- Is your web browser set up to use the proxy?
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:
- Is the tearDownPage function getting executed? (This requires JSUnit version 2.2.)
There is no error in the error console of the web browser.Ed wrote:[/list]
- Are there any errors (e.g., in the web browser's error console)?
Note: I am not instrumenting the js file as,I hope there is no need for instrumentation while running the jscoverage-server.
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: Java script code coverage
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:
Does the tearDownPage function get called?
Code: Select all
http://127.0.0.1:8080/jsunit/testRunner.html?testPage=http://127.0.0.1:8080/test.html&autoRun=true
Re: Java script code coverage
Hi,
I copied the example as you told and accessed the URL.
The function is getting executed and the value for "window.jscoverage_report" shown as "undefined", and the second alert is not displayed.
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();
}
}
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: Java script code coverage
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
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.
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: Java script code coverage
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?