0% found this document useful (0 votes)
20 views

X07a - Integrating Jenkins With Automated Unit Testing

This document discusses integrating automated unit testing into a Jenkins pipeline. It introduces automated testing and its benefits. It then demonstrates setting up a sample PHP application with unit tests in Jenkins pipeline, running the tests on each commit, and viewing test results. Intentionally introducing a bug causes the tests to fail as expected, illustrating the testing process.

Uploaded by

Aqil Syahmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

X07a - Integrating Jenkins With Automated Unit Testing

This document discusses integrating automated unit testing into a Jenkins pipeline. It introduces automated testing and its benefits. It then demonstrates setting up a sample PHP application with unit tests in Jenkins pipeline, running the tests on each commit, and viewing test results. Intentionally introducing a bug causes the tests to fail as expected, illustrating the testing process.

Uploaded by

Aqil Syahmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab-X07a Page 1 of 5

Integrating Jenkins with Automated Unit


Testing
Overview

In Lecture 6, you are introduced to automated testing which is the current industry trend as
promoted by Agile and DevOps/DevSecOps CI/CD process. In this Lab 7a, you are going to learn
how to integrate automated unit testing into Jenkins Pipeline so that you are able to start
incorporating it into your team project.

Outcomes
Upon completion of this lab, you should be able to:
• Write test cases for automated unit testing using xUnit (JUnit, PHPUnit, PyUnit, Mocha, etc)
testing framework
• Create Jenkins pipeline to perform automated unit testing on a simple PHP application
• Start incorporating Jenkins Pipeline with automated testing into your team project

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020
Lab-X07a Page 2 of 5

1: Reference
This lab is based on the video “Running PHPUnit tests after each commit (Get started with Jenkins
part 5“ by Simply Explained posted at https://www.youtube.com/watch?v=68cDNUz7uro.
However, it was presented using different Jenkins environment which you may find it difficult to
follow. Hence, this lab is re-written with enhancement using latest Jenkins Pipeline to help you
understand how to integrate automated unit testing into your team project.

2: Pre-requisite
Git

Download the provided jenkins-phpunit-test.zip file which contains a simple PHP app, a
corresponding unit testing file and a Jenkinsfile. Unzip and initialize it as a Git repository using the
command:
git init

Next, commit with the commands:


git add .
then
git commit -m “Add initial files”

3: Integrating Automated Unit Testing into Jenkins


Pipeline
Create new Jenkins Pipeline

Create a new Pipeline for the simple PHP app in Section 2. (Hopefully you are now familiar with
creating a Jenkins pipeline after trying Lab-X05.)

Run Jenkins Pipeline with Unit Testing

a) Run the Jenkins pipeline which should pass the unit test indicated by OK (1 test, 1
assertion) as shown:

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020
Lab-X07a Page 3 of 5

Enhancing with Test Reporting

b) Update the Jenkinsfile to include test reporting so that your final Jenkinsfile will be similar
as follows:

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020
Lab-X07a Page 4 of 5

c) Commit the update and re-run the Jenkins pipeline. Once completed, exit from Blue
Ocean UI and return to Jenkins classic UI where you will now see the Test Result Trend
with 1 test passed (indicated in blue dot) for Build #2 as shown:

d) Next, let’s intentionally include a bug in the original program by changing the function
turnWheel() in GumballMachine.php as follows:

From:

To:

e) Commit the change and re-run the Jenkins pipeline which will result in failing the unit test
for Build #3 as shown on the Test Result Trend graph on the first page of this hand-out.

f) Scroll down the page where you will see the Latest Test Result icon at the bottom as
shown:

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020
Lab-X07a Page 5 of 5

g) Click the Latest Test Result icon which will shown you information of the failed test.

Hope that you have a better understanding of how to implement automated unit testing now. So try
to start incorporating it into your team project. Enjoy!

END OF DOCUMENT

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy