Automated test generation

Unit test, integration test, E2E test —— lempar code ke OpenClaw, test case auto generate

Nulis test, siapa yang ga pusing?

Testing selalu jadi belakangan

Feature kejar deadline, testing selalu "next release aja deh". Pas live? Wduh, edge case sama sekali ga tercakup.

Nulis mock sampe mual, satu endpoint tergantung tiga service, sekadar mock data aja setengah jam, lebih banyak dari business code.

Coverage report 30%, boss tanya dan cuma bisa bohong "core logic udah tercakup". Sebenarnya happy path aja belum lengkap.

OpenClaw bantu apa soal testing

Pahami kode, generate test yang solid

OpenClaw bukan asal generate beberapa test case buat kamu. Dia analisis function signature, branch logic, exception handling, auto identify edge case dan exception scenario.

Function kamu ada null check? Dia generate test sama null input. Ada loop? Test empty array, single element, banyak data. Ada try-catch? Construct input yang trigger exception.

Plus dia ngerti framework testing kamu —— Jest, Pytest, JUnit, Vitest, generate code langsung bisa jalan, ga perlu manual fix format.

Prompt testing yang langsung bisa dipake

Tiga prompt cover unit test, E2E, load test. Pilih sesuai butuh.

Unit test full coverage Instruksi emas
Analisis semua exported function dan class method di module ini.

Generate unit test lengkap buat setiap function, requirement:
1. Coverage target 90% minimum (statement + branch coverage)
2. Setiap function test: normal input, boundary value, exception input
3. External dependency pake mock, jangan tergantung real DB atau network
4. Test naming clear, format "should xxx when xxx"
5. Add setup/teardown yang perlu

Pake testing framework dan assertion library existing di project, keep style konsisten.
Ini prompt paling populer. Lempar file, test keluar dalam hitungan detik. Coverage 90% bukan ngomong doang, dia catch edge case yang ga pernah kepikir.
E2E login flow test (Playwright) Advanced trick
Write E2E test sama Playwright buat login flow berikut:

Test scenario:
1. Normal login: input username/password benar, verify redirect ke homepage
2. Wrong password: input password salah, verify error message
3. Empty form submit: ga input apa-apa, verify form validation
4. Remember me: click "remember me", close, reopen, verify login state
5. Logout: login terus click exit, verify redirect ke login page

Requirement:
- Pakai Page Object Model pattern
- Add wait strategy yang reasonable, jangan pake sleep
- Screenshot gagal scenario buat debug
E2E test Playwright ribet, especially wait strategy dan selector. Biarkan AI nulis draft pertama, terus adjust sesuai page aktual, efisiensi naik berkali-kali lipat.
API load test script Advanced trick
Generate load test script buat API endpoint berikut (k6 atau Artillery):

Test config:
1. Gradual load: mulai 10 concurrent, nambah 10 tiap 30 detik, max 200 concurrent
2. Duration: total 5 menit
3. Request distribution: 70% read, 20% write, 10% update
4. Metrics record: P50/P95/P99 latency, error rate, throughput

Generate result analysis script, output performance bottleneck report. Kalo P99 > 500ms atau error rate > 1%, mark sebagai butuh optimize.
Load test script biasanya half day dari nol. Prompt ini langsung kasih production-grade config, analysis script juga included.

Test generation: OpenClaw vs Copilot

Dua-duanya bisa generate test, tapi quality jauh beda.

OpenClaw
  • Analisis logic dan branch path lengkap, edge case coverage komplit
  • Ngerti relasi lintas file, mock generation akurat
  • Support specify coverage target, ga capai? Tambahin test case
  • Generate E2E, load test, scenario kompleks dengan script lengkap
VS
Copilot
  • Generate berdasar file current aja, lintas file dependency mudah ketinggalan
  • Mostly generate happy path test aja, edge coverage kurang
  • Mock sering butuh manual fix
  • Scenario kompleks (E2E, load test) support terbatas

Real scenario: tambahin test urgent sebelum live

Jumat jam 4 sore, boss bilang hari ini mesti live
Feature baru dikerjain dua minggu, test coverage baru 20%. QA minta minimal 70% baru boleh launch. Sisa tiga jam aja.
OpenClaw
Lempar core module ke OpenClaw, satu prompt, generate test suite komplit. Auto analisis branch mana yang belum tercakup, tambah boundary test dan exception handling. Tiga jam tapos 80% coverage, QA seneng sign off.
Nulis test manual
Mulai gila-gilaan nulis test, cuma urus relasi dependency aja buang sejam. Mock tulis salah tiga kali, test ga jalan. Akhirnya coverage 45%, QA ga boleh pass, lembur sampe subuh.

Beberapa praktik berguna

💡 Generate test selesai, run sekali, pastiin pass. Ada yang gagal? Copy error message ke OpenClaw, dia fix.
🎯 Jangan sekali generate semua test sekaligus, split per module. Tiap kali fokus satu file, test quality lebih bagus.
Generate test pake Claude Opus 4.6 hasil terbaik, terutama kalo logic kompleks. Simple util function test pake DeepSeek V3.2 cukup, hemat duit.
Case ini membantu kamu?