
Файлы в корне проекта:
settings.gradle:
Код: Выделить всё
include "SayHello.Core", "SayHello.Driver"
Код: Выделить всё
apply plugin: 'java'
apply plugin: 'maven'
allprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'jacoco'
jacoco {
toolVersion = '0.8.14'
}
buildDir = rootDir.canonicalPath + "/build/" + rootProject.relativePath(projectDir.canonicalPath)
version = '1.0.0'
group 'com.example.sayhello'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.13.2'
}
}
rootProject.tasks.each { it.enabled = false }
rootProject.tasks.withType(DefaultTask).each { it.enabled = true }
rootProject.uploadArchives.enabled = false
subprojects {
apply plugin: 'maven'
tasks.withType(Test) {
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
reports {
xml.enabled true
html.enabled true
csv.enabled false
}
}
}
Код: Выделить всё
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Код: Выделить всё
dependencies {
compile project(':SayHello.Core')
}
Код: Выделить всё
package com.example.sayhello;
import com.example.sayhello.core.SayHelloCore;
public class SayHelloDriver {
public static void main(String[] args) {
System.out.println(sayHello());
}
public static String sayHello() {
return SayHelloCore.sayHello();
}
}
Код: Выделить всё
package com.example.sayhello;
import static org.junit.Assert.*;
import org.junit.Test;
public class SayHelloTest {
@Test
public void testSayHello() throws Exception {
assertEquals("Hello", SayHelloDriver.sayHello());
}
}
Код: Выделить всё
compileTestJava.options.encoding = 'UTF-8'
dependencies {
testCompile files('src/test/resources')
}
Код: Выделить всё
package com.example.sayhello.core;
public class SayHelloCore {
public static String sayHello() {
return "Hello";
}
}
Код: Выделить всё
package com.example.sayhello.core;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class SayHelloCoreTest {
@Test
public void testSayHello() throws Exception {
// do nothing - we already have a test in SayHello.Driver
// we want to avoid a redundant test like this:
// assertEquals("Hello", SayHelloCore.sayHello());
}
}
Код: Выделить всё
name: Coverage
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
permissions:
contents: read
jobs:
test-and-coverage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Java
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "8"
cache: gradle
- name: Ensure Gradle wrapper is executable
run: chmod +x ./gradlew
- name: Run tests and generate merged JaCoCo report
run: ./gradlew --no-daemon jacocoTestReport
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
verbose: true

Однако в Codecov покрытие от SayHelloCore полностью игнорируется:


Есть ли решение добавить покрытие зависимых проектов, кроме добавления теста в зависимый проект?
Подробнее здесь: https://stackoverflow.com/questions/798 ... and-jacoco
Мобильная версия