I'm using Jasmine as the testing framework for my AngularJS application. I run the tests with the help of Grunt & KarmaJS. KarmaJS also generates the code coverage with the help of karma-coverage.
Now I've created a model for configuaration data, which I also have to instantiate for other tests. Because of this instantiation I get a code coverage for this file although I haven't done any tests for it. Only because while the test run all of the lines were used, the coverage is 100%.
Now the question: Is there a way to specify in my tests which files they cover?
In PHP Unit there is an #covers annotation which specifies what code is covered with the test.
Thx
Since karma-coverage uses Istanbul under the hood, all configuration for Istanbul should work for karma-coverage.
In Istanbul, you can specify that a block of code be ignored for coverage purposes. You can try placing something like this at the top of your file:
/* istanbul ignore next */
I haven't tried this myself, but I'd bet that this or something similar would do what you want it to do.
Related
I've publish a tool which based on jest to test my code and collect coverage.
I found the same file's coverage in entire coverage report can't match single one file coverage report since I use v8 coverage provider.
This is my coverage of entire project.
It can't match the result that I run jest in single one file.
I think it maybe v8 coverage problem and also try out babel coverage, It seems OK.
So, the problems is that I can't remember why I use v8 instead of babel becuase leave on a warnning in my tool.
Is there any problems if I switch v8 to babel?
I am trying to set up code coverage for my node.js unit tests.
What I am trying to do is this:
Use WebStorm for running tests
use Mocha (and co-mocha) as a testing framework
Use yield and generators for making my test code more readable
See the code coverage of my source code via the WebStorm UI (hoping to see my source code files color-coded according to code coverage)
The first two points are going fine, the third one is tripping me up.
Unfortunately WebStorm doesn't provide coverage support for Mocha:( Please follow WEB-10373 for updates
I have a built version of a React module that I'm testing successfully with Jasmine but when I try to use Istanbul to determine my tests coverage it shows that I'm only testing the Require.js Define lines of the code.
In particular the render function is clearly being called in my test (as I have tests that are passing on a div that must be being rendered) but is showing as not being covered in Istanbul.
Any ideas why this might be?
N.B. I am not testing the JSX files only their built JS versions.
I just came into a Node.js project that has a ton of unit tests, most of which, unfortunately, are outdated and don't run. There's no test runner or any kind of code coverage tool implemented, and it is certainly not in my scope of work to refactor everything.
That being said, that doesn't stop me from wanting to check the code coverage of my work. I've looked at both Istanbul and Blanket and can't find a way to only have them run certain unit tests. Surely, there is a way so that I can get a report that, obviously, reports a very low percentage of coverage, but that I can dive into certain files and such (those that my tests hit) to ensure my code is throughly tested.
With istanbul.js, you can easily get the coverage information this by for example specifying the following command (Following example uses mocha but it will be similar for any test framework):
istanbul cover node_modules/.bin/_mocha -- -u exports -R spec test/test1.spec.js test/test2.spec.js
You can also specify all the tests in particular sub-directory eg: test/yourfeaturetest/*.spec.js. You also have something like test/myfeature/**/*.spec.js to cover all the tests in the test/myfeature directory including tests that could have been created recursively in sub-directories.
As for me, I use gulp and thus utilize plugins such as gulp-istanbul and run tests and coverage via gulp tasks.
I wanna gauge unit test coverage for Javascript.
jscoverage is one of the most useful tool.
However, jscoverage can only gauges which the code pass or not on unit test.
I wanna gauge coverage including logic.
How should I gauge unit test coverage for JS ?
BlanketJS is a fantastic code coverage tool that works well with QUnit. I've been using it for about a year now.
For larger projects, I also have QUnit and Blanket integrated with Grunt so I can run my tests, and check my code coverage thresholds from the command line, as well as CI solutions like TravisCI.
There was no existing Grunt plugin that fit my needs, so I wound up writing my own Grunt plugin. The plugin supports "enforcement" of a minimum threshold, or else the Grunt task fails.
I wrote a blog post with all the details here: http://www.geekdave.com/2013/07/20/code-coverage-enforcement-for-qunit-using-grunt-and-blanket/