AI के साथ यूनिट टेस्ट लिखना

AI को आपका टेस्ट सूट जनरेट करने दें। वास्तव में बग पकड़ने वाले टेस्ट लिखने का एक व्यावहारिक वर्कफ्लो।

3 steps
codingdeveloper-tools
1

कोड लिखने से पहले सभी टेस्ट केस सूचीबद्ध करें

कोई भी टेस्ट कोड लिखने से पहले AI से फंक्शन के लिए हर टेस्ट केस सूचीबद्ध करवाएं।

Example prompt
List all test cases I should write for this function. Include: happy path scenarios, edge cases (empty input, null, zero, negative numbers, max values), error cases (invalid input, exceptions), and boundary conditions. Do not write test code yet — just list the cases. Function:

[PASTE FUNCTION]
2

केस लिस्ट से टेस्ट कोड जनरेट करें

अब केस लिस्ट वापस AI को पास करें और उससे वास्तविक टेस्ट कोड लिखने के लिए कहें।

Example prompt
Write [JEST/PYTEST/VITEST/etc.] unit tests for the following function, covering all these test cases: [PASTE CASE LIST FROM PREVIOUS STEP]. Use descriptive test names. Mock external dependencies. Include setup/teardown if needed. Function:

[PASTE FUNCTION]
3

मौजूदा टेस्ट में गैप्स खोजने के लिए AI से कहें

अपनी मौजूदा टेस्ट फ़ाइल और सोर्स कोड पेस्ट करें। AI से पूछें कि कौन से परिदृश्य कवर नहीं हैं।

Example prompt
Review my existing tests against the source code and identify: 1) Test cases that are missing, 2) Tests that test the wrong thing or have incorrect assertions, 3) Code paths that are not covered, 4) Scenarios that could break in production but are not tested. Source:

[PASTE SOURCE]

Existing tests:

[PASTE TESTS]
Ready to try AI/ML API?
Follow this playbook with the actual tool
View Tool