DEV Community

Cover image for Test Driven Development (TDD) th.
kanthakran
kanthakran

Posted on

3 2

Test Driven Development (TDD) th.

TDD คือ

การสร้าง software ใน scope สั้นๆ โดยเราจะเขียน automate test เอาไว้ให้มัน fail ก่อนเพื่อจะกำหนดการทำงานของโปรแกรมในระดับ function แล้วเขียน code เพื่อให้ผ่าน test (เขียนให้ผ่านก่อน) แล้วเรามา refactor ให้มันดีขึ้นอีกที

tdd

http://newyorkschooltalk.org/wp-content/uploads/2020/02/1_ieVWcSsJmeBbZFo6a_dL5g.png

Step

  1. เขียน test (เพื่อให้เห็น scope ของโปรแกรมของเรา)
  2. run ให้ fail
  3. เขียน code เขียนให้ผ่านก่อน
  4. เทสที่เคย fail จะ pass จากการเขียน code
  5. Refactor แก้ไข ให้ดีขึ้น

ข้อดี

  • มั่นใจของเก่าไม่พัง
  • debug ง่าย
  • requirement ไม่หาย
  • เราจะสามารถมั่นใจได้ว่าโปรแกรมทำงานได้ตรงตามที่เราเขียนจริงๆ

ข้อเสีย

  • นานเพราะต้องศึกษา
  • เสียเวลาเขียนเทสวุ่นเว้อ
  • ใช้ประสบการณ์สูง
  • ประเมิณเวลายาก เพราะต้องรวมเวลาเขียน test

สรุป

มันน้อยใช่ไหมละที่เขียนมา ใช่น้อยมากเลยแต่จริงๆ มองภาพรวมอาจจะง่ายแต่การแตก task สิ่งที่โปรแกรมเราต้องทำให้ละเอียดพอที่จะเขียน test แต่แรกนั้นต้องใช้เวลาในการฝึก การคิด test case ที่ครอบคลุมมากพอก็ไม่ใช่เรื่องง่าย การเขียน code ที่จะทำให้เราสามารถ mock data เพื่อ test ก็ต้องอาศัยแนวคิด จนกระทั่ง step สุดท้าย refactor อาจจะต้องอาศัยความรู้เรื่อง clean code หรือประสบการณ์ ที่มากพอถึงจะสามารถทำออกมาได้ดีได้

อาจจะต้องใช้ ความทุ่มเท ใส่ใจ และ passion เพื่อจะเป็นมืออาชีพ

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay