02 - Code Coverage - eclEmma and JaCoCo
This tutorial describes how to write a smart batch script which capable of identifying class paths, source paths automatically and generate Code Coverage Report.
Source Code is avaiable in bellow :-
SETLOCAL EnableDelayedExpansion ENABLEEXTENSIONS
::ENABLEEXTENSIONS - Ensure command extensions are enabled
::SETLOCAL - Ensure this script won't rewrite any global variable, Ensure localization of all variables going to be declared
::EnableDelayedExpansion - Expand variables at execution time / allow to append
@echo off
cls
echo -------------------------------------------------------
echo ---- C O D E C O V E R A G E A U T O M A T I O N ----
echo -------------------------------------------------------
echo.
set /P info="Do You Want to Enable Print Process Info (Y/N) : "
echo.
echo.
set /p testName="Please Enter Fully Qualified Name of the Test as folder path if package is declared (eg: com/thath/test/TestName) : "
echo.
echo =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
echo.
echo --------------------------------------
echo --- AUTO CLASS PATH SEARCHING STARTED ---
echo --------------------------------------
echo.
::Find class path of all existing .class files recursively
:: /B Bare format (no heading, file sizes or summary).
:: /S include all subfolders.
:: %%F - variable in for loop for storing file path.
:: ~p - path without drive name / ~d - drive name only / ~n - file name only
:: classPATH - variable for future uses. we concatinate values to this variable.
:: !classPATH! - concept called delayed expansion. only if we call our variable in this way for concatinating, it will concat correctly
FOR /F %%F IN ('DIR /B /S "*.class"') DO (SET classPATH=!classPATH!%%~pF;
:: /I - case insensitive, /A - arythmatic comparision
if /I %info% == Y echo %%~pF
if /I %info% == N echo You have disabled Print Process Info...
SET /a countclass+=1)
echo.
if /I %info% == Y echo --- file count : %countclass%
if /I %info% == N echo You have disabled Print Process Info...
echo.
echo --- AUTO CLASS PATH SEARCH COMPLETED ---
echo.
echo =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
echo.
echo --------------------------------------------------
echo --- AUTO SOURCE(java) FILE PATH SEARCHING STARTED ---
echo --------------------------------------------------
echo.
::Find path of all existing .java files recursively
FOR /F %%F IN ('DIR /B /S "*.java"') DO (SET javaPATH=!javaPATH!%%~pF;
if /I %info% == Y echo %%~pF
if /I %info% == N echo You have disabled Print Process Info...
SET /a countjava+=1)
echo.
if /I %info% == Y echo --- file count : %countjava%
if /I %info% == N echo You have disabled Print Process Info...
echo.
echo --- AUTO SOURCE(java) FILE PATH SEARCH COMPLETED ---
echo.
echo =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
echo.
echo Generating jacoco.exec ...
java -javaagent:resource/jacoco/lib/jacocoagent.jar -cp resource/junit-4.10.jar;%classPATH%;resource/hamcrest-all-1.3.jar org.junit.runner.JUnitCore %testName%
echo.
echo Finished Generating JACOCO.EXEC ...
echo.
echo =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
echo.
echo Generating HTML Report
echo Prepare JaCoCoCLI Command ...
::Recursively add [ --classfiles classPath ] to commandExecutable variable and prepare command
set classPATHtemp=%classPATH%
:processClassPathPrepareCommand
for /f "tokens=1* delims=;" %%a in ("!classPATHtemp!") do (
set classPATHtemp=%%b
set commandExecutable=!commandExecutable! --classfiles %%a
)
if not "%classPATHtemp%" == "" goto :processClassPathPrepareCommand
::finally concat last part of the commandExecutable
set commandExecutable=java -jar resource/jacoco/lib/jacococli.jar report jacoco.exec %commandExecutable% --sourcefiles %javaPATH% --html report
::finally execute the commad to generate HTML Report
if /I %info% == Y echo Prepared Command : %commandExecutable%
if /I %info% == N echo You have disabled Print Process Info...
%commandExecutable%
echo.
echo Finished Generating HTML Based Report ...
PAUSE
EXIT
Видео 02 - Code Coverage - eclEmma and JaCoCo автора Программирование: творчество и инновации
Видео 02 - Code Coverage - eclEmma and JaCoCo автора Программирование: творчество и инновации
Информация
5 декабря 2023 г. 14:48:04
00:06:20
Похожие видео