How to achieve Code Coverage through Continuous Integration (Jenkins)?


Continuous Integration Process:

Note : Before starting the code coverage process through ACI using jenkins , Make sure code coverage is working locally through android studio as posted in the below link.


Continuous Integration process represents continuous development, deployment and continuous delivery process. While the developers integrate their codes in a common shared repository frequently (Several time in a day) and each integration can be verified by automated test or automated build.

Advantages:
Integrating regularly is that you can detect errors quickly and locate them more easily.
Time saving process.
Reduce manual effort.

Code Coverage:
Code coverage is the process where we get a clarity on how much percentage of the source code is covered during testing.

Test Coverage:
 Continuous Integration Process with Jenkins:
  • Install Jenkins (MSI/WAR)
Follow given link JENKINS INSTALLATION
  • Create Git_Hub repository / any repository (SVN, TFS, etc.)/ access to Git_Hub source code
  • Android SDK
  • Automation Framework for testing


Step 1:

After Installing Jenkins, go to command prompt and give your Jenkins.war file path.
Then, enter command as “java -jar jenkins.war --httpPort=9090
Where,   “java -jar Jenkins. War” used to initiate the Jenkins and “ --httpPort=9090” used to initiating Jenkins in a customize port
Note: Default port of Jenkins will be “8080”.
Now got to your web browser and enter the URL as http://localhost:9090/.
Step 2:

Before creating any job in jenkins we have to make sure the manage Jenkins configuration.
Manage Jenkins Setting:
Click on Manage Jenkins




Manage Plugins Setting: Where we need to install all the plugins for our ACI process
Go to manage Plugins => Available tab => Search “Gradle” =>Then Install without restart.
Go to manage Plugins => Available tab => Search “Jacoco” =>Then Install without restart.
Go to manage Plugins => Available tab => Search “MSBuild” =>Then Install without restart.
Go to manage Plugins => Available tab => Search “Android Lint” =>Then Install without restart.
Go to manage Plugins => Available tab => Search “Emulator” =>Then Install without restart.
Go to manage Plugins => Available tab => Search “GIT” =>Then Install without restart.

Then, navigate back to manage Jenkins again and click the first option “Configure System

Configure System Setting: 

Where we need to configure some setting related to ACI process.
Go to Global properties section and check the “Environment variable” checkbox.
1.       Environment variable setting

·         For Android SDK
Name: ANDROID_HOME
Value: C:\Users\xxxxx\AppData\Local\Android\sdk

2.       Go to down of the page  ‘Android ’ Section
Give Android SDK ROOT as “C:\Users\xxxxx\AppData\Local\Android\sdk
  
Global Tool Configuration setting:
  •  Go to JDK section and give JDK path

Name: JDK
JAVA_HOME: C:\Program Files\Java\jdk1.8.0_121
  •   Go to GIT installation section

Name: Default
Path to Git executable: git.exe

  •   Click Gradle Installation



  •  Click on MSBUILD section






Step 3:
Create Jobs

1.   First Job
Ex : First job I created as “BuildApp” : Which helps to do building the android app and output should be a build apk which is known as debug .apk

1.       Click on New Item section in Jenkins.
2.       Enter an item name (ex- BuildApp)
3.       Select freestyle project
4.       Then, Click on ‘OK’
5.       Follow below image :



6.       Then Go to Build section.



7.       Then “Publish Android Lint option” & Archive artifacts. (you have to add these options from “Add post build ” section




2.   Second Job
1.       Ex : 2nd  job I created as “StartAutomationTesting” : which helps you to run automation scripts on .apk file.
2.       I have done with appium with c#, that’s why we are using Microsoft visual studio as IDE.
3.       This automation project contains install apk in device and do some functionalities , then close app and quit appium driver.
4.       In Jenkins, MS Build plugin.
5.       Click on New Item section in Jenkins.
6.       Enter an item name (ex- StartAutomationTesting)
7.       Select freestyle project
8.       Then, Click on ‘OK’
9.       Follow below image :
                


10.       


Here the batch command is :
call "C:\Users\105798\Documents\Visual Studio 2013\Projects\Execute.bat"

                        Execute.bat file:
                        "C:\Program Files (x86)\NUnit-2.6.4\bin\nunit-console.exe" "C:\Users\105798\.jenkins\workspace\startAutomationtesting\AppiumDemoCodeCov\bin\Debug\Unicron Selenium Demo.dll"

"C:\Program Files (x86)\NUnit-2.6.4\bin\nunit-console.exe"
This indicates nunit console file.

C:\Users\xxxxx\.jenkins\workspace\startAutomationtesting\AppiumDemoCodeCov\bin\Debug\xxxxx Selenium Demo.dll"
This indicates your project dll fie inside Jenkins.




1.   Third Job

a.       Click on New Item section in Jenkins.
b.      Enter an item name (ex- GenerateReports)
c.       Select freestyle project
d.      Then, Click on ‘OK’
e.      Select “jacoco coverage report
f.        Follow below image :
   


Jacoco report plugin setting in Jenkins:

Generate coverage report using ant(with jacoco task) or Jenkins (jacoco plugin) by using following:-
Copy classes from "D:\coverage\app\build\intermediates\classes\debug"
Copy source from "D:\coverage\app\\src\main\java"
Copy exec file from "D:\coverage\mycoverage.exec"
Add below as Exclusions:-
**/R.class,**/R$*.class,**/BuildConfig.*,**/Manifest*.*,**/*Fragment*.*,**/*Activity$*.*

Build a continuous process so that Jenkins will do the job one by one.
EX:
My first job is “BuildApp” .
Second Job is “startAutomationTesting
Third     job is “GenerateReports

 Click on BuildApp job you created => Configure => Go to “Add post build action”section and select “Build other project” => give the automation testing job name(“startautomationtesting”)
Follow below Image :
   

On the same way now in 2nd job configure the 3rd job.
So that we can archive a continuous process, which contains building application, automation testing and generating the code coverage reports.

      
Execution Process for All the jobs in Jenkins.

Go to “BuildApp” job in Jenkins , click on build now option.
Logs will display like below logs :


Started by user sunil sahoo
Building in workspace C:\Users\105798\.jenkins\workspace\BuildApp
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/sunilkumarqa/BuildingCodeCoverage16thoct.git # timeout=10
Fetching upstream changes from https://github.com/sunilkumarqa/BuildingCodeCoverage16thoct.git
 > git.exe --version # timeout=10
 > git.exe fetch --tags --progress https://github.com/sunilkumarqa/BuildingCodeCoverage16thoct.git +refs/heads/*:refs/remotes/origin/*
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision 4d63a226bd3e925551420328168649f68d592d52 (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f 4d63a226bd3e925551420328168649f68d592d52
Commit message: "5th"
 > git.exe rev-list 4d63a226bd3e925551420328168649f68d592d52 # timeout=10
[Gradle] - Launching build.
[BuildApp] $ cmd.exe /C "C:\Users\105798\.jenkins\workspace\BuildApp\gradlew.bat clean build && exit %%ERRORLEVEL%%"
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
:clean
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2511Library
:app:prepareComAndroidSupportAppcompatV72511Library
:app:prepareComAndroidSupportDesign2511Library
:app:prepareComAndroidSupportRecyclerviewV72511Library
:app:prepareComAndroidSupportSupportCompat2511Library
:app:prepareComAndroidSupportSupportCoreUi2511Library
:app:prepareComAndroidSupportSupportCoreUtils2511Library
:app:prepareComAndroidSupportSupportFragment2511Library
:app:prepareComAndroidSupportSupportMediaCompat2511Library
:app:prepareComAndroidSupportSupportV42511Library
:app:prepareComAndroidSupportSupportVectorDrawable2511Library
:app:prepareComAndroidSupportTransition2511Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard
:app:javaPreCompileDebug
:app:compileDebugJavaWithJavac
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:unzipJacocoAgent
:app:transformClassesWithJacocoForDebug
:app:transformClassesWithDexForDebug
:app:mergeDebugJniLibFolders
:app:transformNativeLibsWithMergeJniLibsForDebug
:app:transformNativeLibsWithStripDebugSymbolForDebug
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug
:app:validateSigningDebug
:app:packageDebug
:app:assembleDebug
:app:checkReleaseManifest
:app:prepareReleaseDependencies
:app:compileReleaseAidl
:app:compileReleaseRenderscript
:app:generateReleaseBuildConfig
:app:generateReleaseResValues
:app:generateReleaseResources
:app:mergeReleaseResources
:app:processReleaseManifest
:app:processReleaseResources
:app:generateReleaseSources
:app:incrementalReleaseJavaCompilationSafeguard
:app:javaPreCompileRelease
:app:compileReleaseJavaWithJavac
:app:compileReleaseNdk UP-TO-DATE
:app:compileReleaseSources
:app:mergeReleaseShaders
:app:compileReleaseShaders
:app:generateReleaseAssets
:app:mergeReleaseAssets
:app:transformClassesWithJacocoForRelease
:app:transformClassesWithDexForRelease
:app:mergeReleaseJniLibFolders
:app:transformNativeLibsWithMergeJniLibsForRelease
:app:transformNativeLibsWithStripDebugSymbolForRelease
:app:processReleaseJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForRelease
:app:packageRelease
:app:assembleRelease
:app:assemble
:app:lint
Ran lint on variant debug: 181 issues found
Ran lint on variant release: 181 issues found
Wrote HTML report to file:///C:/Users/105798/.jenkins/workspace/BuildApp/app/build/reports/lint-results.html
Wrote XML report to file:///C:/Users/105798/.jenkins/workspace/BuildApp/app/build/reports/lint-results.xml
:app:incrementalDebugUnitTestJavaCompilationSafeguard UP-TO-DATE
:app:javaPreCompileDebugUnitTest
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:compileDebugUnitTestJavaWithJavac UP-TO-DATE
:app:processDebugUnitTestJavaRes UP-TO-DATE
:app:compileDebugUnitTestSources UP-TO-DATE
:app:mockableAndroidJar
:app:assembleDebugUnitTest
:app:testDebugUnitTest UP-TO-DATE
:app:incrementalReleaseUnitTestJavaCompilationSafeguard UP-TO-DATE
:app:javaPreCompileReleaseUnitTest
:app:preReleaseUnitTestBuild UP-TO-DATE
:app:prepareReleaseUnitTestDependencies
:app:compileReleaseUnitTestJavaWithJavac UP-TO-DATE
:app:processReleaseUnitTestJavaRes UP-TO-DATE
:app:compileReleaseUnitTestSources UP-TO-DATE
:app:assembleReleaseUnitTest
:app:testReleaseUnitTest UP-TO-DATE
:app:test UP-TO-DATE
:app:check
:app:build
 
BUILD SUCCESSFUL
 
Total time: 1 mins 51.339 secs
Build step 'Invoke Gradle script' changed build result to SUCCESS
[BuildApp] $ cmd /c call C:\Users\105798\AppData\Local\Temp\jenkins6184005795648724994.bat
 
C:\Users\105798\.jenkins\workspace\BuildApp>COPY C:\Users\105798\.jenkins\workspace\BuildApp\app\build\outputs\apk /Y E:\apk_files /Y  
C:\Users\105798\.jenkins\workspace\BuildApp\app\build\outputs\apk\app-debug.apk
C:\Users\105798\.jenkins\workspace\BuildApp\app\build\outputs\apk\app-release-unsigned.apk
        2 file(s) copied.
 
C:\Users\105798\.jenkins\workspace\BuildApp>exit 0 
[android-lint] Collecting Android Lint files...
[android-lint] Searching for all files in C:\Users\105798\.jenkins\workspace\BuildApp that match the pattern **/lint-results*.xml
[android-lint] Parsing 1 file in C:\Users\105798\.jenkins\workspace\BuildApp
[android-lint] Successfully parsed file C:\Users\105798\.jenkins\workspace\BuildApp\app\build\reports\lint-results.xml with 181 unique warnings and 0 duplicates.
[android-lint] Computing warning deltas based on reference build #116
Archiving artifacts
Triggering a new build of startAutomationtesting
Finished: SUCCESS





No comments:

Post a Comment

Copyright © 2017 QALEARNINGGUIDE.COM || ALL RIGHTS RESERVED