Перейти к содержимому

Write Unit Tests With ChatGPT That Actually Catch Bugs (Not Just Green Checkmarks)

promptcore

0:00 / 0:00

Write Unit Tests With ChatGPT That Actually Catch Bugs (Not Just Green Checkmarks)

0 просмотров · 4 дн. назад
promptcore
5 подписчиков
0 просмотров · 4 дн. назад
All your tests pass. Green everywhere. And the bug ships anyway, because the tests ChatGPT wrote only check that a result exists, not that it's right. Five copy-paste prompt moves to write unit tests with AI that actually catch bugs: give it the rules (not just the code), list the test cases first, pick the expected answers yourself, break the code on purpose to see if a test fails, and run every test yourself. Works in ChatGPT, Claude, Gemini, or any chat assistant, with Jest, pytest, or whatever test framework you use. #UnitTesting #ChatGPT #AIForDevelopers What you will learn: 1. GIVE IT THE RULES, NOT JUST THE CODE: paste the function plus what it should do (inputs, outputs, bad input), so it tests your rules instead of copying your bugs 2. LIST THE CASES FIRST: normal, edge (zero, empty, max, off-by-one) and bad input, before any test code; you add what it missed, and unknowns become EXPECTED: ASK ME 3. YOU PICK THE EXPECTED ANSWERS: expected values come from your rules as plain values (like 90), never from running the code or copying its formula 4. BREAK THE CODE ON PURPOSE: plant one small bug at a time (the idea behind mutation testing); if no test turns red, add one that does 5. RUN THEM YOURSELF: in a normal chat it may not have run anything; paste the real test output and ask whether the code or the test is wrong Chapters: 0:00 Intro: all green, bug ships 0:18 The trap: tests that check nothing 0:36 Why it happens 0:57 The fix: five moves 1:11 1 · Give it the rules 1:29 Vague ask vs code + rules 1:54 Template A · test against the rules 2:14 2 · List the cases first 2:53 Template B · case list 3:12 3 · You pick the expected answers 3:30 Copied formula vs plain answer 3:52 Template C · real expected values 4:12 4 · Break the code on purpose 4:48 Template D · plant a bug 5:04 5 · Run them yourself 5:38 Template E · real test output 5:56 Which move, when 6:19 Honest catch: green isn't proof 6:45 Recap 7:03 Your move Copy-paste A) Give it the rules TEST this function against the rules below, not against its own code. RULES: [inputs, outputs, and what bad input should do]. FRAMEWORK: [Jest, pytest, or yours]. One behavior per test. CODE: [paste the function here] Copy-paste B) List the cases first LIST the test cases first. No test code yet. GROUP them: normal, edge, bad input. FOR edges, try zero, empty, the max, and off-by-one. IF you don't know the expected result, write EXPECTED: ASK ME. Copy-paste C) You pick the expected answers EXPECTED values come from my rules, never from running the code. WRITE each one as a plain value, like 90, not a formula. IF a rule doesn't say, mark it EXPECTED: ASK ME. NO copying logic from the function into the test. Copy-paste D) Break it on purpose BREAK this function in 3 small ways, one at a time. FOR each, tell me which test should fail. IF no test would fail, write a test that does. SHOW each change as a one-line edit I can undo. Copy-paste E) Run them yourself HERE is the real output from my test run: [paste it]. FOR each failure, say if the code or the test is wrong, and why. DON'T change an expected value just to make a test pass. DON'T claim tests pass. I'll run them. How this differs from our other videos: Treat prompts like code (tiny tests that catch drift): that one tests your prompts. Here you test your code, and AI helps write the tests. Stop one-shot coding with AI (spec, plan, diff, test): that one is about getting AI to write the code. Here the code exists, and the job is tests that would catch it being wrong. Debug with a bug report: that one fixes a bug you already found. Here you write tests so the next bug gets caught before it ships. Honest catch: Even with these moves, AI can write a test that checks the wrong thing, or miss a case you never mentioned. Passing tests don't prove your code is right. Before you paste work code into any chat assistant, check your team's rules for AI tools, and take out secrets like keys, tokens, and passwords. Read every test before you commit it. Made-up demos: the discount function, its formula and rules, the test cases, the planted bugs, the test counts and the assistant replies shown in the video are illustrative examples written for this video, not real code or real AI output. Accuracy note: these are prompt habits, not features of any AI product or test framework. Jest and pytest are only examples. Some assistants can run code in some modes; still run the tests in your own project. Bracketed parts are placeholders. Habits, not guarantees. Like and subscribe for more practical AI workflows. #UnitTesting #ChatGPT #AIForDevelopers #UnitTests #SoftwareTesting #TestCases #EdgeCases #MutationTesting #Jest #Pytest #JavaScript #Python #AICoding #CodingWithAI #ChatGPTForDevelopers #ChatGPTPrompts #Claude #Gemini #PromptEngineering #CopyPastePrompts #CodeQuality #SoftwareEngineering #Programming #promptcore #AIproductivity