# Test-Driven Development

## 😢 ปัญหา

1. เคยรู้สึกปวดกบาลกันไหม เวลาที่เราเขียนๆงานอยู่แล้ว**เพื่อนมาบอกว่าเจอ bug ในงานของเรา** แล้วพอเราแก้ให้เขาเสร็จ มันก็เดินมาบอกว่า**ไอ้ที่แก้เมื้อกี้มันทำตรงนั้นพังด้วยอ่ะ** ด้วยจิตวิญญาณของโปรแกรเมอร์ของเราเลยต้อง**ตามไปแก้ให้มันต่อ** แล้วพอเราแก้เสร็จ เจอเพื่อนเรามันก็เดินมาบอกว่า อะเค **bug ล่าสุดหายละ แต่ bug ตัวแรกสุดอะกลับมาอีกละ** วนเวียนกันไปเรื่อยๆ&#x20;
2. ตอนที่เราเทสกันแต่ละรอบก็ใช้เวลาเทสนานม๊วก เช่น**กว่า developer จะส่งให้ฝั่ง tester ได้เทส** และ**กว่าที่ tester จะส่งผลกลับมาให้ developer ได้** นี่ยังไม่รวมว่าพวก tester จะต้องใช้เวลาทำความเข้าใจว่าจะเทสยังไงด้วยนะ รวมๆแล้ว**เขียนโปรแกรมหรือแก้ bug เสร็จ 1 ครั้ง กว่าจะรู้ผลว่ามี bug หรือเปล่าอาจจะใช้เวลามากกว่า 1 วัน**ก็ได้!&#x20;

## 😄 วิธีแก้ปัญหา

ปัญหาที่เกิดขึ้นมันชี้ว่า **โค้ดที่เราเขียนมันไม่ถูกนำไปเทส** หรือ **เทสที่นำไปทดสอบมันไม่ครอบคลุม** และในบางทีอาจจะหมายถึงเรา**ไม่มีสิ่งที่เรียกว่า Test automation** ก็ได้ทำให้การเทสแต่ละครั้งมันช้าม๊วก ดังนั้นจากที่ว่ามาในเรื่องนี้เราจะมาดูกันว่าการพัฒนาซอฟต์แวร์โดยใช้หลัก **Test-Driven Development** หรือ **TDD** มันจะมาช่วยลดปัญหาที่ว่ามายังไงบ้างกันเน่อ

{% hint style="info" %}
เชื่อไหมว่า 80% ของคนเขียนโค้ดส่วนใหญ่ไม่สนใจเรื่องนี้เพราะมองว่ามันเสียเวลาที่จะทำ แต่สุดท้ายงานก็จะออกมาไม่มีคุณภาพ bug เยอะเต็มไปหมด และไม่สามารถจะเพิ่มความสามารถใหม่ๆเข้าไปในโปรแกรมได้ แต่ถ้าเราได้ลองศึกษาและทำมันเป็นชีวิตประจำวันไปแล้วละก็จะพบว่า มันเร็วกว่าการเขียนแบบเดิมหลายเท่าเสียอีก (ผมไม่ได้มโนเอานะ มันมีวิจัยเรื่องนี้จริงๆ)
{% endhint %}

{% hint style="success" %}
สไลด์ที่ใช้ในการสอน\
<https://gitpitch.com/saladpuk/test-driven-development>
{% endhint %}

## 🧭 ความรู้ในการจัดการปลาตัวนี้

{% content-ref url="/pages/-LmTLSlAFjT4KVFX2u\_P" %}
[1.มารู้จักกับ TDD กันดีกว่า](/software-testing/tdd101/intro.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmTNYhm6solNbabYt3N" %}
[2.Test cases เขาเขียนกันยังไงนะ](/software-testing/tdd101/test-cases.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmTRp5Ky1lE3D6QHMhq" %}
[3.เครื่องมือในการทดสอบ](/software-testing/tdd101/xunit01.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmTUZfRl6dCR5Rp3UiU" %}
[4.การใช้ Theory และ InlineData](/software-testing/tdd101/xunit02.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmTVtMW9RahIYI8q5DZ" %}
[5.โค้ดที่ทดสอบได้](/software-testing/tdd101/testable-code.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmT\_PkTNrcmU2TX9kJS" %}
[6.Mantra of TDD](/software-testing/tdd101/mantra-of-tdd.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmTdqqcw4To7cuatIGh" %}
[7.Functional & None-Functional testing](/software-testing/tdd101/fun-n-nonefun-testing.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmTgIdC6\_qWYqnm46Dv" %}
[8.Manual vs Automation testing](/software-testing/tdd101/manual-vs-automation.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmTivnRqKdLrqYRXL3d" %}
[9.Automation Frameworks in .NET](/software-testing/tdd101/automation-frameworks.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmTlfu-IGuHnMDyADgl" %}
[10.Mock Framework](/software-testing/tdd101/mock-framework.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmTmkVj1zgQi6brw472" %}
[11.มาเรียนการใช้ Moq กันเถอะ](/software-testing/tdd101/moq101.md)
{% endcontent-ref %}

{% content-ref url="/pages/-LmToBO5y-7lMKD7laCx" %}
[12.สรุป](/software-testing/tdd101/summary.md)
{% endcontent-ref %}

## 🎥 วีดีโอทั้งหมดของคอร์สนี้

[@Youtube Test-Driven Development (TDD)](https://www.youtube.com/playlist?list=PLUjAn8nwWniiL3ToFK8PfmAo8U6IoGAkg)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.saladpuk.com/software-testing/tdd101.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
