Tests First with a Coding Assistant
Write the tests yourself, let the assistant make them pass, and keep the specification in your hands
A taste of a lesson
I wrote tests for a discount function. The assistant's code passes, but it has 'if price == 100' in it. Is that a problem?
Yes. That is overfitting: the code matches your test inputs rather than implementing the rule. Your tests probably used 100 as the main example, and the assistant found the shortest path to green. Add more cases with different prices, including boundaries like the minimum order for a discount, and a property style test: for any price, the discounted price is never negative and never above the original. Then ask for a general implementation. What is the actual discount rule, stated in one sentence?
Written by the teacher as an example. In your lesson the tutor answers your own questions, and like any AI it can be wrong.
What you will be able to do
- Turn requirements into concrete test cases including edge cases and failures
- Run a tests first loop with an assistant implementing against fixed tests
- Detect weakened tests, special cased inputs and over mocked tests
- Use characterisation and property based tests where they fit
- Judge when test first is the wrong approach
Lesson plan
- 1 Tests as the specification Understand why tests make AI assisted work clearer and safer. Start
- 2 From requirement to test cases Write examples that capture normal behaviour, edges and failures. Start
- 3 Red, then green with an assistant Run the loop: failing tests, implementation, passing tests. Start
- 4 Spotting cheating and overfitting Catch implementations that pass tests without solving the problem. Start
- 5 Refactoring and regression tests Improve code safely and lock in every bug fix. Start
- 6 When tests first does not fit Choose a different approach for exploration and unclear requirements. Start
Try asking
About this tutor
For developers who want AI speed without losing confidence in correctness. In test first work, the tests are the specification: if you write or carefully approve them, the assistant's job becomes clear and checkable. You will practise turning requirements into test cases, writing tests for edge cases and failures, asking the assistant to implement against them, preventing it from changing tests to make them pass, and refactoring safely once tests are green. We also cover when to let the assistant propose tests and how to review those proposals critically.
Reviews
4.5
2 ratingsSample
- Alicia N.Sample
Writing the tests myself and letting the assistant implement has made me trust AI code far more. The overfitting examples were eye opening.
- Viktor H.Sample
Practical and not preachy about TDD. The 'when it does not fit' lesson was refreshing.
About the teacher
I teach how to review, test, refactor and secure code written with AI help
9 tutors 320 lessons taught Sample
I care about what happens after the code is generated. My background is in code review, testing and application security, and I teach developers to treat AI output as a draft from a fast, confident colleague who has never seen production. We practise reading diffs carefully, writing tests before asking for code, refactoring old systems in safe steps and spotting...
See Ilse's profile and tutorsMore like this
Other tutors on the same or nearby topics.