How use JSCoverage with modified jsUnitTestManager
-
- Posts: 10
- Joined: 2009-02-09 9:46 am
How use JSCoverage with modified jsUnitTestManager
Hi,
I have a custom unittest window(instead testRunner.html), which load all test functions into array. User can choice test class (example: testClients). This class has constructor test (example: ClientsUnitTest) and prototype functions (example: testAddClients...).
All test classes inherit ClientUnitTest manager. This manager (Example: TestManager) is equal to containerTestFrame(jsUnitTestManager.js).
I tried use JSCoverage, but Summary tab display 0 results, because the code hasn't js files - only objects with functions. The function "jscoverage_recalculateSummaryTab"(file: jscoverage.js) hasn't files into variable "cc".
How I can use JSCoverage to calculate jsunit javascript code coverage for object?
I have a custom unittest window(instead testRunner.html), which load all test functions into array. User can choice test class (example: testClients). This class has constructor test (example: ClientsUnitTest) and prototype functions (example: testAddClients...).
All test classes inherit ClientUnitTest manager. This manager (Example: TestManager) is equal to containerTestFrame(jsUnitTestManager.js).
I tried use JSCoverage, but Summary tab display 0 results, because the code hasn't js files - only objects with functions. The function "jscoverage_recalculateSummaryTab"(file: jscoverage.js) hasn't files into variable "cc".
How I can use JSCoverage to calculate jsunit javascript code coverage for object?
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: How use JSCoverage with modified jsUnitTestManager
Where is the JavaScript code located? Not the code for the test framework, but the code for the System Under Test - where is that coming from?
-
- Posts: 10
- Joined: 2009-02-09 9:46 am
Re: How use JSCoverage with modified jsUnitTestManager
An execuble file(.exe file) runs an application with browser control. With javascript loaded all javascript files - objects and functions from xml file. An exe file located into win folder(Example: C:\source\win) and javascript files located into script folder(example: C:\source\script, C:\source\script\app...). The browser control loaded main.html located into C:\source\script\app\html. The UnitTest folder located into C:\source\UnitTests. Is this information enough?
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: How use JSCoverage with modified jsUnitTestManager
OK, are these JavaScript files the files being tested? Or are they the test code? Or are they the code for the test framework?jsto wrote:javascript files located into script folder(example: C:\source\script, C:\source\script\app...).
If these are the files being tested, you will have to instrument those. Probably you want to do something like this:
Code: Select all
jscoverage.exe C:\source\script C:\source\script-instrumented
-
- Posts: 10
- Joined: 2009-02-09 9:46 am
Re: How use JSCoverage with modified jsUnitTestManager
Hi,
thank you for your help. I tried this but it was unsuccessful. May be this type of project can not use JSCoverage. I have javasript files outside html file.
About my test framework - I have different type of jsunit testing window and jsUnitTestManager.
This UnitTestManager loaded all objects and their functions from .js files and I tested functions as call a object - not working with .js files.
thank you for your help. I tried this but it was unsuccessful. May be this type of project can not use JSCoverage. I have javasript files outside html file.
About my test framework - I have different type of jsunit testing window and jsUnitTestManager.
This UnitTestManager loaded all objects and their functions from .js files and I tested functions as call a object - not working with .js files.
-
- Posts: 10
- Joined: 2009-02-09 9:46 am
Re: How use JSCoverage with modified jsUnitTestManager
Now i try again. Successful only for js files included into main.html file.
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: How use JSCoverage with modified jsUnitTestManager
Are the JavaScript functions defined outside of a .js file somehow? For example, are they embedded in an XML file? In that case JSCoverage will not work, as the jscoverage.exe program will not be able to find them.
If the functions are defined in .js files, then it should work. It should not matter whether they are included in the HTML file or not. Just make sure you run jscoverage.exe to create instrumented .js files, and make sure your application is using these instrumented files (not the originals).
If the functions are defined in .js files, then it should work. It should not matter whether they are included in the HTML file or not. Just make sure you run jscoverage.exe to create instrumented .js files, and make sure your application is using these instrumented files (not the originals).
-
- Posts: 10
- Joined: 2009-02-09 9:46 am
Re: How use JSCoverage with modified jsUnitTestManager
All javascript code as objects and functions are defined in .js files.
An xml file contains only path+file name for .js and html files.
An executable file loaded one js file and that file loaded all other js files in the browser control.
The application hierarchy is for exapmle c:\script, c:\script\app, c:\script\clients, c:\script\app\bla....
Аfter jscoverage folder having created I started jscoverage.html and wrote path to html file. This html contained only a few js files. For other .js files (loaded only as objects) can not display coverage information.
An xml file contains only path+file name for .js and html files.
An executable file loaded one js file and that file loaded all other js files in the browser control.
The application hierarchy is for exapmle c:\script, c:\script\app, c:\script\clients, c:\script\app\bla....
Аfter jscoverage folder having created I started jscoverage.html and wrote path to html file. This html contained only a few js files. For other .js files (loaded only as objects) can not display coverage information.
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: How use JSCoverage with modified jsUnitTestManager
This path must point to the instrumented .js files.jsto wrote:All javascript code as objects and functions are defined in .js files.
An xml file contains only path+file name for .js and html files.
How do you specify where the "loader" js file will load its files from? Is that from the XML file? This must also be the instrumented .js files.jsto wrote:An executable file loaded one js file and that file loaded all other js files in the browser control.
I suspect the loader is, for some reason, loading files from the original directory and not the instrumented directory.jsto wrote:The application hierarchy is for exapmle c:\script, c:\script\app, c:\script\clients, c:\script\app\bla....
Аfter jscoverage folder having created I started jscoverage.html and wrote path to html file. This html contained only a few js files. For other .js files (loaded only as objects) can not display coverage information.
-
- Posts: 10
- Joined: 2009-02-09 9:46 am
Re: How use JSCoverage with modified jsUnitTestManager
All js files are instrumented as:
/* automatically generated by JSCoverage - do not edit */
if (! top._$jscoverage) {
top._$jscoverage = {};
}
var _$jscoverage = top._$jscoverage;
if (! _$jscoverage['app/box.js']) {
_$jscoverage['app/box.js'] = [];
_$jscoverage['app/box.js'][19] = 0;.....
But when I wrote main html file in the url textbox(example: file:///C:/Source/main.html) loaded only .js files in this file. The main application is c++ application. This application loaded other js files.
/* automatically generated by JSCoverage - do not edit */
if (! top._$jscoverage) {
top._$jscoverage = {};
}
var _$jscoverage = top._$jscoverage;
if (! _$jscoverage['app/box.js']) {
_$jscoverage['app/box.js'] = [];
_$jscoverage['app/box.js'][19] = 0;.....
But when I wrote main html file in the url textbox(example: file:///C:/Source/main.html) loaded only .js files in this file. The main application is c++ application. This application loaded other js files.
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: How use JSCoverage with modified jsUnitTestManager
How does this C++ application work? I presume it works like this:jsto wrote:But when I wrote main html file in the url textbox(example: file:///C:/Source/main.html) loaded only .js files in this file. The main application is c++ application. This application loaded other js files.
- Run C++ application
- C++ application loads browser control
- Browser control loads jscoverage.html
- jscoverage.html loads file:///C:/Source/main.html
- file:///C:/Source/main.html includes "loader" .js file
- "loader" .js file loads other .js files
-
- Posts: 10
- Joined: 2009-02-09 9:46 am
Re: How use JSCoverage with modified jsUnitTestManager
No, it isn't correct.
1. run C++ application
2. C++ application loads browser control
3. Browser control loads main.html
4. One button(for test) load jscoverage.html(from instrumented folder)
5. JSCoverage displays "Browser" tab.
I cann't load jscoverage.html into browser control, because when main.html loaded, a browser control used functions from this main page(included .js files,which jscoverage can execute).
I cann't load main.html from instrumented folder too.
I will try different scenarios.
1. run C++ application
2. C++ application loads browser control
3. Browser control loads main.html
4. One button(for test) load jscoverage.html(from instrumented folder)
5. JSCoverage displays "Browser" tab.
I cann't load jscoverage.html into browser control, because when main.html loaded, a browser control used functions from this main page(included .js files,which jscoverage can execute).
I cann't load main.html from instrumented folder too.
I will try different scenarios.
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: How use JSCoverage with modified jsUnitTestManager
OK, that is slightly different but I think that can work too.jsto wrote:No, it isn't correct.
1. run C++ application
2. C++ application loads browser control
3. Browser control loads main.html
4. One button(for test) load jscoverage.html(from instrumented folder)
5. JSCoverage displays "Browser" tab.
If you cannot change the C++ application to load main.html from the instrumented folder, can you (temporarily) move the original folder and replace it with the instrumented folder?jsto wrote: I cann't load jscoverage.html into browser control, because when main.html loaded, a browser control used functions from this main page(included .js files,which jscoverage can execute).
I cann't load main.html from instrumented folder too.
Something like this:
- move C:\source\script C:\source\script-original
- move C:\source\script-instrumented C:\source\script
-
- Posts: 10
- Joined: 2009-02-09 9:46 am
Re: How use JSCoverage with modified jsUnitTestManager
I don't want to change c++ code. I tried this before, but c++ loaded instrumented js code and display errors (Microsoft JScript runtime error: 'top' is undefined). Perhaps I need some tool to coverage js objects.
The different scenarios is:
- adds jscoverage button into instrumented main.html file.
- loads instrumented main.html
- calls jscoverage.html
- displays only included .js(in main.html) files with changeable statistic.
The different scenarios is:
- adds jscoverage button into instrumented main.html file.
- loads instrumented main.html
- calls jscoverage.html
- displays only included .js(in main.html) files with changeable statistic.
-
- Posts: 120
- Joined: 2008-10-11 6:52 pm
Re: How use JSCoverage with modified jsUnitTestManager
I think I understand what is going on now. You are saying that the other .js files - these are being executed outside the browser control? If that is the case, JSCoverage will not work, as it assumes code is being executed in a web browser.jsto wrote:I don't want to change c++ code. I tried this before, but c++ loaded instrumented js code and display errors (Microsoft JScript runtime error: 'top' is undefined). Perhaps I need some tool to coverage js objects.
The different scenarios is:
- adds jscoverage button into instrumented main.html file.
- loads instrumented main.html
- calls jscoverage.html
- displays only included .js(in main.html) files with changeable statistic.
You might be able to modify JSCoverage (or modify the instrumented code generated by jscoverage) to get it to work, but you would have to do 2 things:
- Modify the statements from instrumented code that assume a browser (the statements referencing "top")
- Write code to display the code coverage statistics (since jscoverage.html will not work)