0% found this document useful (0 votes)
89 views23 pages

WK8-Test Driven Development and CICD

The document discusses Test Driven Development (TDD) and Continuous Integration/Continuous Delivery (CI/CD). It defines TDD as a software development process where test cases are fully developed and executed before production code is written. The TDD cycle involves writing a test, seeing it fail, then writing code to pass the test and refactoring the code if needed. CI/CD combines continuous integration, where code is frequently integrated and tested in a shared repository, with continuous delivery or deployment, where code can be released to production either manually or automatically. Automated testing is a key part of CI to ensure code quality during integration.
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)
89 views23 pages

WK8-Test Driven Development and CICD

The document discusses Test Driven Development (TDD) and Continuous Integration/Continuous Delivery (CI/CD). It defines TDD as a software development process where test cases are fully developed and executed before production code is written. The TDD cycle involves writing a test, seeing it fail, then writing code to pass the test and refactoring the code if needed. CI/CD combines continuous integration, where code is frequently integrated and tested in a shared repository, with continuous delivery or deployment, where code can be released to production either manually or automatically. Automated testing is a key part of CI to ensure code quality during integration.
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/ 23

SF332

การทดสอบและประกันคุณภาพซอฟต์แวร์
Software Testing and Quality Assurance

Week 8
Test Driven Development (TDD)
& Continuous Integration and Configuration Management (CI/CD)

SF332 Software Testing and Quality Assurance 1


Agenda

Test Driven Development (TDD)

Continuous Integration
and Configuration Management (CI/CD)

SF332 Software Testing and Quality Assurance 2


Test Driven Development
What is test-driven development?

TDD Cycle & Methodology

Refactoring

F.I.R.S.T. principle for unit testing

Benefits & Limitations


SF332 Software Testing and Quality Assurance 3
What is Test-driven development (TDD) ?
• TDD is a software development process,
where test cases are fully developed first and tracking all software development by
repeatedly testing the software against all test cases.
• TDD is not
software testing methodology

1. Test

3.
2 code
Refactor

SF332 Software Testing and Quality Assurance 4


TDD Cycle & Methodology
• TEST FIRST – CODE LAST
You may not write
production code unless
you’ve first written a falling
unit test.
• TEST MORE - CODE MORE
You may not write more
of a unit test than is
sufficient to fail
• TEST AGAIN – CODE AGAIN
You may not write more
production code than is
sufficient to make the falling
unit test pass.
SF332 Software Testing and Quality Assurance 5
Refactoring

SF332 Software Testing and Quality Assurance 6


Refactoring
• Nature of Software

Maintainability
???

Refactoring !
Version 3
Version 2
Version 1

Software

SF332 Software Testing and Quality Assurance 7


Refactoring
• Process of Removing Bad Smell
Extract Method
Extract Class
1. Detecting
the Locations ????

of Bad Smell

2. Identifying Extract
Method
the refactoring
3. Applying the
4. Assessing the refactoring appropriate
impact on the software quality refactoring

SF332 Software Testing and Quality Assurance 8


Refactoring
• Long Method Bad Smell

Preserve Whole Object

Introduce Parameter object

Extract Method
Replace Temp with Query

Decompose Conditional

SF332 Software Testing and Quality Assurance 9


F.I.R.S.T. principle for unit testing

SF332 Software Testing and Quality Assurance 10


TDD Benefits

SF332 Software Testing and Quality Assurance 11


Limitation

SF332 Software Testing and Quality Assurance 12


Referenace
• https://chavp.wordpress.com/tag/tdd/
• https://www.thaiprogrammer.org/2019/01/what-is-tdd/
• https://www.somkiat.cc/practice-tdd/
• https://www.somkiat.cc/tpse2014-test-driven-development/
• Test Driven Development - Clean Code that works, Consulthinkspa, 2015,
https://www.slideshare.net/Consulthink/test-driven-development-45064705?qid=7c222305-22ca-4025-a0f3-
327a5888a000&v=&b=&from_search=9

• Test-driven Development, Wikipedia, as of Mar 3, 2022, https://en.wikipedia.org/wiki/Test-driven_development

• [Podcast] ทา TDD ถ้าอยากได้ software ที่มีคุณภาพ https://www.youtube.com/watch?v=re4CmYYIyYE


• พาฝึกทา Test Driven Development 1 - โจทย์ Basic https://www.youtube.com/watch?v=viItmkK067g

SF332 Software Testing and Quality Assurance 13


Agenda

Test Driven Development (TDD)

Continuous Integration
and Configuration Management (CI/CD)

SF332 Software Testing and Quality Assurance 14


Continuous Integration
and Configuration Management (CI/CD)
• Continuous integration is
a coding philosophy and set of practices
that drive development teams to
implement small changes and check in
code to version control repositories
frequently.

In Software Engineering, CI/CD or CICD is


the combined practices of
continuous integration (CI) and
either continuous delivery or continuous
deployment (CD).
SF332 Software Testing and Quality Assurance 15
CI: คืออะไร
• Continuous Integration คือกระบวนการรวบรวม Source Code ของ วิธีการที่แนะนา การ Merge code ให้ถี่ขึ้น
Developer เข้ามาเพื่อตรวจสอบว่า Source Code ที่มีการแก้ไขนั้นถูกต้อง • แบ่ง feature ให้เล็กลง เพื่อให้ใช้เวลา Code ให้น้อย
หรือไม่ โดยทางานเป็นแบบอัตโนมัติ (automation process) ตั้งแต่
การ build การ merged และการทดสอบ เพื่อให้มั่นใจว่าจะไม่เกิด • ใช้หลักการ TDD มาช่วย เช่น 1 กิจกรรมมี test case กากับ
ข้อผิดพลาดเกิดขึ้น • ใช้ Feature flag มาช่วย กรณีเรายัง พัฒนาไม่เสร็จ แต่จาเป็นต้อง
การทดสอบใน CI นี้ถือเป็นส่วนสาคัญเพราะจะทาให้เรามั่นใจว่า Merge code โดยที่ไม่กระทบต่อภาพรวม
Source Code ที่เรา Merge มานั้นมีข้อผิดพลาดหรือไม่ โดยการทดสอบจะ
ทางานเป็นแบบอัตโนมัติ (Automated Testing) อาจจะประกอบไปด้วย
• Unit Test
• Validating Test
• Formatting Test
• Functional Test
• Integration Test
• End-to-end Test

SF332 Software Testing and Quality Assurance 16


CD: Continuous Delivery
หรือ Continuous Deployment คืออะไร
• Continuous Delivery จะเป็นการ Deploy ซอฟต์แวร์แต่ใช้วิธีการ Manual Deploy •Continuous Deployment จะเป็นการ Deploy ซอฟต์แวร์แต่ใช้
คือเตรียมพร้อมสาหรับการ Deploy อาจจะเพียงแค่คลิกปุ่มก็ Deploy ได้แล้วแต่ที่ยังไม่ วิธีการ Automated Deploy หรือทาเป็นแบบอัตโนมัติทั้งหมด
Deploy ทันทีทันใดนั้นก็อาจจะต้องรอ Confirm กับทาง Business ถึงวันเวลาที่จะ Deploy กระบวนการนี้ถึงแม้จะทาค่อนข้างยากโดยเฉพาะขัน้ ตอนการทดสอบ
หรือ Test script ที่ใช้ตรวจสอบจากกระบวนการ CI นั้นไม่ครอบคลุมเพียงพอทาให้ Tester ซอฟต์แวร์เพราะในการทดสอบนั้นจะต้องใช้ Test script ทั้งหมดยิ่ง
ขอเวลาในการตรวจสอบเพิ่มเติม
ซอฟต์แวร์ที่มีขนาดใหญ่หรือซอฟต์แวร์ที่มีความซับซ้อนอาจจะต้อง
คานึงถึงการทดสอบที่หลากหลายเช่น Regression test, Security
Test, API test, Performance test ซึ่งการสร้าง Test script ก็อาจะ
เป็นสิ่งที่ยากแล้วไหนยังต้องเจอกับความท้าทายกับ Test script ที่ต้อง
Stable อีกด้วย แต่หากองค์กรไหนมีวิธีการจัดการและสามารถทาเป็น
Auto Deployment ได้จริงก็ถือเป็นความประสบสาเร็จอย่างมาก

Pic ref: https://www.atlassian.com/continuous-delivery/principles/continuous-integration-vs-delivery-vs-deployment


SF332 Software Testing and Quality Assurance 17
เริ่มทา CI/CD อย่างไร
CI CD
• ทา unit test (ใช้แนวทาง TDD) • ทา Test case โดยหารือกับ QA / IT security ก่อน
• ทาการทดสอบ ใช้ Feedback loop เพื่อแก้ bug • ทา test script อื่นๆ ที่สามารถทา Automate ได้
• ทุก commit ที่ขึ้น repository ต้องทางานได้เสมอ ก่อน delivery
• พยายาม Merge code ให้บ่อย และ ลดขนาด Feature
• Run test case ทั้งหมด

Idea Execution

Feedback
Feedback loop
SF332 Software Testing and Quality Assurance 18
สรุป
การใช้ Continuous Integration และ Continuous
Deployment ช่วยให้ทีมพัฒนาสะดวกและเร็วขึ้นมาก และ
ส่งเสริมกับเรื่องการส่งมอบงานเป็นรอบและส่งให้ได้ไว
เพื่อให้มีการ feedback เร็ว ดังนั้น การใช้เวลาศึกษาและตั้ง
ระบบขึ้นมาอีกสักหน่อย มันจะช่วยงานเราได้ในระยะยาว

ขั้นตอนอื่นๆที่ต้องศึกษาเพิ่ม เช่น Security, Test, git push


ไปพักไว้ที่ dev branch ก่อน, การ Deploy ไปยัง Stating
Server เพื่อทา Acceptant Test แล้วค่อย merge git เข้าสู่
master branch และ deploy Production และอื่นๆ เป็นต้น

• รูปจาก
http://www.bogotobogo.com/DevOps/DevOps_CI_CD_
Pipeline_Sample.php
SF332 Software Testing and Quality Assurance 19
ตัวอย่าง Tool ที่รองรับ CI/CD

SF332 Software Testing and Quality Assurance 20


Reference
• SOFTWARE ENGINEERING,IAN SOMMERVILLE https://cloud-ace.co.th/blogs/w0w7e1-ci-cd-
https://www.slideshare.net/software-engineering-book/ch25-configuration-management services-google-cloud
• CONFIGURATION MANAGEMENTIS OLD AND BORING https://blog.pjjop.org/ci-cd-pipeline-with-gitlab-
https://www.slideshare.net/lnxchk/configuration-management-is-old-and-boring server-for-devops-team/
• CI & CD AWS SUMMIT https://www.techtalkthai.com/first-step-of-ci-cd-
for-software-development-with-metro-cloud/
https://www.slideshare.net/AmazonWebServices/session-7-continuous-integration-amp-
continuous-delivery-on-aws-raghuraman-balachandran

https://www.youtube.com/watch?v=h6UKJ9JGPX4
• https://www.somkiat.cc/ci-cd-with-jenkins-at-swpark/
• https://www.slideshare.net/MichaelSolberg/continuous-integration-for-configuration-management
• https://www.techterrotor.com/2021/06/cicd.html
• https://myifew.com/4072/automation-deploy-git-bitbucket-jenkins/
• https://www.press.in.th/continuous-integration-continuous-deployment/

SF332 Software Testing and Quality Assurance 21


SF332 Software Testing and Quality Assurance 22
Assignment 8
• MS-Team- TDD and CI/CD
• จงอธิบายต่อไปนี้ (2 คะแนน)
1. TDD คืออะไร และ มีประโยชน์ในการทาการทดสอบซอฟต์แวร์อย่างไร
2. CI /CD คืออะไร
3. ยกตัวอย่าง TDD และ CI/CD (คะแนนพิเศษ 1 คะแนน)
• โดยส่งไฟล์แนบ การตั้งชื่อไฟล์ รหัสน.ศ._Assignment8

SF332 Software Testing and Quality Assurance 23

You might also like