code manipulation : 코드 커버리지 측정하기(jacoco)

This commit is contained in:
haerong22
2021-02-18 19:07:45 +09:00
parent f88be42e74
commit 6533f5fd47
4 changed files with 129 additions and 0 deletions

75
code-manipulation/pom.xml Normal file
View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>code-manipulation</artifactId>
<version>1.0-SNAPSHOT</version>
<name>code-manipulation</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- jacoco -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,20 @@
package org.example;
public class Moim {
int maxNumberOfAttendees;
int numberOfEnrollment;
public boolean isEnrollmentFull() {
if (maxNumberOfAttendees == 0) {
return false;
}
if (numberOfEnrollment < maxNumberOfAttendees) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,19 @@
package org.example;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
/**
* Unit test for simple App.
*/
public class AppTest {
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue()
{
assertTrue( true );
}
}

View File

@@ -0,0 +1,15 @@
package org.example;
import org.junit.Assert;
import org.junit.Test;
public class MoimTest {
@Test
public void isFull() throws Exception {
Moim moim = new Moim();
moim.maxNumberOfAttendees = 100;
moim.numberOfEnrollment = 10;
Assert.assertFalse(moim.isEnrollmentFull());
}
}