** I'm learning and I write some simple tests, just to know how it works. When I want to build a Gradle project I had this issue: Rule violated for bundle java-gradle-examples: lines covered ratio is 0.0, but expected minimum is 0.5
Can anyone want to help me?**
GRADLE.BUILD:
code
plugins {
id 'java'
id 'jacoco'}
group = 'pl.something'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '16'
repositories {
mavenCentral()
}
dependencies {
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.6'
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version:'5.0.0-M4'}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
test {
useJUnitPlatform()
testLogging {
events "skipped", "failed"
}
finalizedBy jacocoTestReport
}
jacoco {
toolVersion = "0.8.7"
}
jacocoTestReport {
dependsOn test
reports {
xml.required = false
csv.required = false
html.outputLocation = layout.buildDirectory.dir('jacocoReports')
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.5
}
}
}
}
check.dependsOn jacocoTestCoverageVerification
My Test Class :
code
@Test
void add() {
int left = 2;
int right = 1;
int expected = 3;
Integer result = left + right;
Assertions.assertEquals(expected, result);
}
@Test
void subtract() {
int left = 2;
int right = 1;
int expected = 1;
Integer result = left - right;
Assertions.assertEquals(expected, result);
}
@Test
void multiply() {
int left = 2;
int right = 1;
int expected = 2;
Integer result = left * right;
Assertions.assertEquals(expected, result);
}
@Test
@Disabled("I disabled this test for example")
void divide() {
int left = 2;
int right = 1;
int expected = 2;
Integer result = left / right;
Assertions.assertEquals(expected, result);
}
}
And my Main.class:
code
public class Main {
public static void main(String[] args) {
System.out.println(Calculator.add(1, 2));
Calculator calculator = new Calculator();
Calculator.substract(5, 3);
}
}