Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Add tests for jacoco library
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaitanya-Chatla committed Nov 20, 2018
1 parent 78f4164 commit 667d9a7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
83 changes: 83 additions & 0 deletions test/jacoco.js
@@ -0,0 +1,83 @@
(function (fs, parser, helper, path) {
'use strict';

var expect = helper.chai.expect;
var jacocoData = fs.readFileSync(__dirname + '/mock/jacoco.xml').toString();
var noStatsJacocoData = fs.readFileSync(__dirname + '/mock/no-lines.xml').toString();
describe('Jacoco Parser', function () {

it('should be to parse jacoco data', function () {
return expect(parser.getParser('jacoco').parse('',jacocoData))
.to.eventually.satisfy(function (data) {
expect(data).to.deep.equal({
total: 23,
fileReports: [
{
filename: 'com/wmbest/myapplicationtest/MainActivity.java',
coverage: {
8: 0,
11: 2,
12: 1,
13: 7,
18: 0,
19: 0,
20: 0,
25: 0,
26: 0,
34: 0,
37: 0,
38: 0,
41: 0
},
total: 23 }]
});
return true;
});
});

it('should be able to parse jacoco data with path prefix', function () {
return expect(parser.getParser('jacoco').parse(path.normalize('my-project' + path.sep), jacocoData))
.to.eventually.satisfy(function (data) {
expect(data).to.deep.equal({
total: 23,
fileReports: [
{
filename: 'my-project/com/wmbest/myapplicationtest/MainActivity.java',
coverage: {
8: 0,
11: 2,
12: 1,
13: 7,
18: 0,
19: 0,
20: 0,
25: 0,
26: 0,
34: 0,
37: 0,
38: 0,
41: 0
},
total: 23 }]
});
return true;
});
});

it('should be able to parse jacoco data without lines', function() {
return expect(parser.getParser('jacoco').parse('', noStatsJacocoData))
.to.eventually.satisfy(function (data) {
expect(JSON.stringify(data)).to.equal(JSON.stringify({
total: 0,
fileReports: [
{
filename: path.normalize('com/wmbest/myapplicationtest/MainActivity.java'),
coverage: {},
total: 0
}]
}));
return true;
});
});
});
}(require('fs'), require('../lib/coverageParser'),require('./helper'), require('path')));
16 changes: 16 additions & 0 deletions test/jacoco2.js
@@ -0,0 +1,16 @@
(function (fs, parser, helper) {
'use strict';
var expectedCoverage = 40;
var expect = helper.chai.expect;
var jacocoData = fs.readFileSync(__dirname + '/mock/jacoco2.xml').toString();

describe('Jacoco Parser', function () {
it('should be able to parse jacoco data with empty files', function () {
return expect(parser.getParser('jacoco').parse('', jacocoData))
.to.eventually.satisfy(function (data) {
expect(data.total).to.equal(expectedCoverage);
return true;
});
});
});
}(require('fs'), require('../lib/coverageParser'), require('./helper')));

0 comments on commit 667d9a7

Please sign in to comment.