Materi 28 - Programming dan Data Science

Testing dan Debugging

Bedanya kode amatir dan profesional. Unit test, integration test, debugging mindset.

Durasi 26 Menit Level intermediate Kurikulum 30 Materi

1. Kenapa Testing

Tangkap bug sebelum production. Confidence saat refactor. Dokumentasi behavior code. Mempercepat development jangka panjang. Tim yang test serius lebih cepat ship feature.

2. Unit Test

Test smallest unit (function). Cepat, isolated, deterministic. Pakai assertion library (pytest, JUnit, Jest). Aim minimal 70 persen code coverage untuk core business logic.

3. Integration Test

Test multiple component bekerja bersama. Slower dari unit. Pakai untuk: API endpoint, database interaction, third-party service. Penting tapi jangan terlalu banyak (slow CI).

4. Test Driven Development

Tulis test dulu, baru implementation. Red (test gagal), Green (buat lulus), Refactor. Memaksa thinking lebih baik. Disiplin tinggi tapi result kode lebih bersih.

5. Debugging

Step 1: reproduce bug konsisten. Step 2: lokalisasi (binary search). Step 3: fix root cause, bukan symptom. Step 4: tambah test untuk prevent regression. Pakai debugger, bukan print statement.

Tugas Praktik

  1. Tulis 5 unit test untuk function di project
  2. Setup CI dengan auto-run test setiap commit
  3. Praktek TDD untuk 1 fitur kecil
  4. Debug 1 bug pakai debugger
  5. Increase code coverage dari 20 persen ke 70 persen

Rangkuman