Java & 배경지식/기본상식

바이트코드 조작

레알윙 2020. 6. 7. 18:03
반응형

바이트 코드 조작

코드 커버리지? 테스트 코드가 확인한 소스 코드를 %

 

JaCoCo 설정 방법

1. pom.xml에 의존성 추가

<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>
    </executions>
</plugin>

 

2. target에 있는 site폴더에 존재하는 index.html 실행

index.html 오른쪽클릭 -> open with -> web Brower클릭

 

3.  결과

 

 

4. 추가

커버리지 만족 못할시 빌드 실패하도록 설정

        <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>
반응형