Skip to content

Commit

Permalink
Support jacoco aggregate (#405)
Browse files Browse the repository at this point in the history
* used "@7sean68/jacoco-parse" instead of "jacoco-parse"
to support jacoco aggregate

* added multimodule test

* fix version

Co-authored-by: Ryan Luker <ryanluker@outlook.com>

* added multimodule java to example

* added notice blocks to copied files

---------

Co-authored-by: Ryan Luker <ryanluker@outlook.com>
  • Loading branch information
7sean68 and ryanluker authored May 22, 2023
1 parent e1d2df2 commit 5a162d4
Show file tree
Hide file tree
Showing 15 changed files with 409 additions and 194 deletions.
2 changes: 1 addition & 1 deletion @types/jacoco-parse/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ declare namespace parse {
}
}

declare module "jacoco-parse" {
declare module "@7sean68/jacoco-parse" {
export = parse;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Shows you a html preview of your coverage reports in your editor.
See [examples directory](example) on how to setup a project.

- [Java](example/java)
- [Multimodule Java](example/multimodule-java)
- [PHP](example/php)
- [Python](example/python)
- [Nodejs](example/node)
Expand Down
1 change: 1 addition & 0 deletions example/multimodule-java/jacoco.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.1//EN" "report.dtd"><report name="module3"><sessioninfo id="admin-ac7aa039" start="1682364826758" dump="1682364827009"/><sessioninfo id="admin-d1fdb3fa" start="1682364827853" dump="1682364828128"/><sessioninfo id="admin-f4fe0db" start="1682364829397" dump="1682364830516"/><group name="module1"><package name="com/praveen/samples/jacoco/multimodule"><class name="com/praveen/samples/jacoco/multimodule/Module1Class" sourcefilename="Module1Class.java"><method name="&lt;init&gt;" desc="()V" line="3"><counter type="INSTRUCTION" missed="0" covered="3"/><counter type="LINE" missed="0" covered="1"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="convertToString" desc="(I)Ljava/lang/String;" line="9"><counter type="INSTRUCTION" missed="0" covered="3"/><counter type="LINE" missed="0" covered="1"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="convertToLong" desc="(I)J" line="13"><counter type="INSTRUCTION" missed="0" covered="5"/><counter type="LINE" missed="0" covered="1"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="concatenate" desc="(I)Ljava/lang/String;" line="26"><counter type="INSTRUCTION" missed="0" covered="18"/><counter type="LINE" missed="0" covered="3"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="getNumber" desc="()I" line="32"><counter type="INSTRUCTION" missed="0" covered="3"/><counter type="LINE" missed="0" covered="1"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="setNumber" desc="(I)V" line="36"><counter type="INSTRUCTION" missed="0" covered="4"/><counter type="LINE" missed="0" covered="2"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="getResult" desc="()Ljava/lang/String;" line="40"><counter type="INSTRUCTION" missed="0" covered="3"/><counter type="LINE" missed="0" covered="1"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="setResult" desc="(Ljava/lang/String;)V" line="44"><counter type="INSTRUCTION" missed="0" covered="4"/><counter type="LINE" missed="0" covered="2"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><counter type="INSTRUCTION" missed="0" covered="43"/><counter type="LINE" missed="0" covered="12"/><counter type="COMPLEXITY" missed="0" covered="8"/><counter type="METHOD" missed="0" covered="8"/><counter type="CLASS" missed="0" covered="1"/></class><sourcefile name="Module1Class.java"><line nr="3" mi="0" ci="3" mb="0" cb="0"/><line nr="9" mi="0" ci="3" mb="0" cb="0"/><line nr="13" mi="0" ci="5" mb="0" cb="0"/><line nr="26" mi="0" ci="13" mb="0" cb="0"/><line nr="27" mi="0" ci="3" mb="0" cb="0"/><line nr="28" mi="0" ci="2" mb="0" cb="0"/><line nr="32" mi="0" ci="3" mb="0" cb="0"/><line nr="36" mi="0" ci="3" mb="0" cb="0"/><line nr="37" mi="0" ci="1" mb="0" cb="0"/><line nr="40" mi="0" ci="3" mb="0" cb="0"/><line nr="44" mi="0" ci="3" mb="0" cb="0"/><line nr="45" mi="0" ci="1" mb="0" cb="0"/><counter type="INSTRUCTION" missed="0" covered="43"/><counter type="LINE" missed="0" covered="12"/><counter type="COMPLEXITY" missed="0" covered="8"/><counter type="METHOD" missed="0" covered="8"/><counter type="CLASS" missed="0" covered="1"/></sourcefile><counter type="INSTRUCTION" missed="0" covered="43"/><counter type="LINE" missed="0" covered="12"/><counter type="COMPLEXITY" missed="0" covered="8"/><counter type="METHOD" missed="0" covered="8"/><counter type="CLASS" missed="0" covered="1"/></package><counter type="INSTRUCTION" missed="0" covered="43"/><counter type="LINE" missed="0" covered="12"/><counter type="COMPLEXITY" missed="0" covered="8"/><counter type="METHOD" missed="0" covered="8"/><counter type="CLASS" missed="0" covered="1"/></group><group name="module2"><package name="com/praveen/samples/jacoco/multimodule"><class name="com/praveen/samples/jacoco/multimodule/Module2Class" sourcefilename="Module2Class.java"><method name="&lt;init&gt;" desc="()V" line="3"><counter type="INSTRUCTION" missed="0" covered="3"/><counter type="LINE" missed="0" covered="1"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="convertToDouble" desc="(I)D" line="6"><counter type="INSTRUCTION" missed="0" covered="5"/><counter type="LINE" missed="0" covered="1"/><counter type="COMPLEXITY" missed="0" covered="1"/><counter type="METHOD" missed="0" covered="1"/></method><method name="convertToFloat" desc="(I)F" line="10"><counter type="INSTRUCTION" missed="5" covered="0"/><counter type="LINE" missed="1" covered="0"/><counter type="COMPLEXITY" missed="1" covered="0"/><counter type="METHOD" missed="1" covered="0"/></method><counter type="INSTRUCTION" missed="5" covered="8"/><counter type="LINE" missed="1" covered="2"/><counter type="COMPLEXITY" missed="1" covered="2"/><counter type="METHOD" missed="1" covered="2"/><counter type="CLASS" missed="0" covered="1"/></class><sourcefile name="Module2Class.java"><line nr="3" mi="0" ci="3" mb="0" cb="0"/><line nr="6" mi="0" ci="5" mb="0" cb="0"/><line nr="10" mi="5" ci="0" mb="0" cb="0"/><counter type="INSTRUCTION" missed="5" covered="8"/><counter type="LINE" missed="1" covered="2"/><counter type="COMPLEXITY" missed="1" covered="2"/><counter type="METHOD" missed="1" covered="2"/><counter type="CLASS" missed="0" covered="1"/></sourcefile><counter type="INSTRUCTION" missed="5" covered="8"/><counter type="LINE" missed="1" covered="2"/><counter type="COMPLEXITY" missed="1" covered="2"/><counter type="METHOD" missed="1" covered="2"/><counter type="CLASS" missed="0" covered="1"/></package><counter type="INSTRUCTION" missed="5" covered="8"/><counter type="LINE" missed="1" covered="2"/><counter type="COMPLEXITY" missed="1" covered="2"/><counter type="METHOD" missed="1" covered="2"/><counter type="CLASS" missed="0" covered="1"/></group><counter type="INSTRUCTION" missed="5" covered="51"/><counter type="LINE" missed="1" covered="14"/><counter type="COMPLEXITY" missed="1" covered="10"/><counter type="METHOD" missed="1" covered="10"/><counter type="CLASS" missed="0" covered="2"/></report>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright {yyyy} {name of copyright owner}

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// this file is copied from https://github.com/PraveenGNair/jacoco-multi-module-sample/


package com.praveen.samples.jacoco.multimodule;

public class Module1Class {

private int number;
private String result;

public String convertToString(int inputNumber) {
return String.valueOf(inputNumber);
}

public long convertToLong(int inputNumber) {
return Long.valueOf(inputNumber);
}

/**
* A concatenation function. We will not write unit/integration test for this function. Rather we
* would invoke this method from module3 i.e functional tests using cucumber, To see if we are
* getting overall test coverage.
*
* @param inputNumber any number.
* @return self conatenated number in string.
*/
public String concatenate(int inputNumber) {
// Just some random operation
String result = convertToString(inputNumber) + convertToLong(inputNumber);
this.setResult(result);
return result;
}

public int getNumber() {
return number;
}

public void setNumber(int number) {
this.number = number;
}

public String getResult() {
return result;
}

public void setResult(String result) {
this.result = result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright {yyyy} {name of copyright owner}

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// this file is copied from https://github.com/PraveenGNair/jacoco-multi-module-sample/


package com.praveen.samples.jacoco.multimodule;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class Module1ClassIntegrationTest {

@Test
public void testConvertToLongIntegrationTestTwo() {
Module1Class module1Class = new Module1Class();
assertEquals(180L, module1Class.convertToLong(180));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright {yyyy} {name of copyright owner}

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// this file is copied from https://github.com/PraveenGNair/jacoco-multi-module-sample/


package com.praveen.samples.jacoco.multimodule;

import org.junit.Test;
import org.junit.experimental.categories.Category;

import static org.junit.Assert.assertEquals;

public class Module1ClassTest {
@Test
public void testConvertToStringUnitTestOne() {
Module1Class domainClass1 = new Module1Class();
assertEquals( "190", domainClass1.convertToString( 190));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright {yyyy} {name of copyright owner}

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// this file is copied from https://github.com/PraveenGNair/jacoco-multi-module-sample/


package com.praveen.samples.jacoco.multimodule;

public class Module2Class {

public double convertToDouble(int inputNumber) {
return Double.valueOf(inputNumber);
}

public float convertToFloat(int inputNumber) {
return Float.valueOf(inputNumber);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright {yyyy} {name of copyright owner}

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// this file is copied from https://github.com/PraveenGNair/jacoco-multi-module-sample/


package com.praveen.samples.jacoco.multimodule;

import static junit.framework.TestCase.assertEquals;

import org.junit.Test;


public class Module2ClassIntegrationTest {
@Test
public void testConvertFloatIntegrationTestTwo() {
Module2Class module2Class = new Module2Class();
assertEquals( 129f, module2Class.convertToFloat( 129));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright {yyyy} {name of copyright owner}

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// this file is copied from https://github.com/PraveenGNair/jacoco-multi-module-sample/


package com.praveen.samples.jacoco.multimodule;

import static junit.framework.TestCase.assertEquals;

import org.junit.Test;

public class Module2ClassTest {

@Test
public void testConvertDoubleUnitTestOne() {
Module2Class module2Class = new Module2Class();
assertEquals(103.0, module2Class.convertToDouble(103));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright {yyyy} {name of copyright owner}

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// this file is copied from https://github.com/PraveenGNair/jacoco-multi-module-sample/


package cucumbertest;

import com.praveen.samples.jacoco.multimodule.Module1Class;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class ConcatenateSteps {
private Logger logger = LoggerFactory.getLogger(ConcatenateSteps.class);

private Module1Class module1Class;

@Given("^that an integer (\\d+)$")
public void setNumber(int number) throws Throwable {
logger.info( "Given: that: " + number);
module1Class = new Module1Class();
module1Class.setNumber(number);

}

@When("^number (\\d+) is self concatenated$")
public void concatenateNow(int number) throws Throwable {
logger.info( "When: number: " + number);
module1Class.concatenate(number);
}

@Then("^The concatenated output for number (\\d+) should be (.*)$")
public void calculationDone(int number, String result) throws Throwable {
assertThat(number, is(module1Class.getNumber()));
assertEquals(result, module1Class.getResult());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright {yyyy} {name of copyright owner}

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// this file is copied from https://github.com/PraveenGNair/jacoco-multi-module-sample/


package cucumbertest;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = "cucumbertest",
strict = true//to suppress unwanted warnings related to cucumber
)
public class ConcatenateTest {

}
Loading

0 comments on commit 5a162d4

Please sign in to comment.