Giriş
Agent jar dosyasını GitHub veya Maven Central sayfasından indiririz
CLI jar dosyasını GitHub sayfasından indiririz
Örnek
Şöyle yaparız. Burada jacoco.exec dosyası üretilir
java -jar myApp.jar -javaagent:/some/path/jacocoagent.jar
Dosyayı HTML olarak formatlamak için şöyle yaparız
java -jar jacococli.jar report jacoco.exec [options]
destfile seçeneği
Örnek
Şöyle yaparız
version: '3.7'services:contract-first-service:image: ${SERVICE_GROUP}/${SERVICE_NAME}:${SERVICE_TAG}ports:- 4000:4000volumes:- type: bindsource: ./build/jacocotarget: /jacocoenvironment:- JAVA_TOOL_OPTIONS=-javaagent:/jacoco/org.jacoco.agent-runtime.jar=destfile=/jacoco/componentTest.exec- SPRING_PROFILE=${SPRING_PROFILE}
Açıklaması şöyle
1. we bind the build/jacoco folder into the container at the /jacoco location. This means, if we place the Jacoco agent in the build/jacoco location, we can access it when we start the application. Also, is we write the coverage report to this location, we will have access to it outside of the container.2. we override the JAVA_TOOL_OPTIONS to attach the Jacoco agent to the applications JVM, and output the coverage report to /jacoco/componentTest.exec. This means the coverage report, due to the volume binding in step 1, will end up in build/jacoco when the test stops.
Şöyle yaparız
javaagent:/path/to/jacocoagent.jar=includes=tech.picnic.*,output=tcpserver,address=*
Açıklaması şöyle. Burada JaCoCo bir TCP sunucusu başlatıyor ve bağlananlara çıktıyı gönderiyor
This enables the JaCoCo Java agent and configures it to only instrument classes in our tech.picnic.* packages. .... We also configure JaCoCo to write to incoming TCP connections through tcpserver, which we will use to interact with the agent. Using the server, we can fetch the data at any time while the pod is alive.Note: As we expose a server here, security is important. By default, the JaCoCo server listens on port 6300. By setting address=* we only allow connections from local addresses. We do not expose port 6300 in our containers and services.
Hiç yorum yok:
Yorum Gönder