Let tests set the target

Módulo 2: Work with AI on a real codebase

Conteúdo do curso

Esta aula ainda não está no seu idioma, então aqui está em inglês.

Teste rápido

Guess first, no penalty. You ask an AI to fix a failing test. It changes the test's expected total from "$45.00" to "$50.00", and now everything passes. What happened?

A test is your spec in code: it says what correct means, in a form a machine can check. That makes it the best target you can give an AI. Write the test first, watch it fail, then ask the AI to write code until it passes. This is called test-first, or test-driven development.

It only works if the target stays still. AI tools that are told to "make the tests pass" sometimes take the shortest path, which is changing the test. So say three things in the request:

  • Which files it may change: the code, not the tests.
  • The rule: never edit, skip or delete a test.
  • The way out: if it thinks a test is wrong, stop and explain why.

Then check the diff (the list of lines the change adds and removes) for any test file before you accept the work. If a test really is wrong, you change it yourself, with a reason in the commit.

O resto desta aula faz parte do Learn Pro

O primeiro módulo de cada curso é grátis. O Learn Pro libera todas as aulas de todos os cursos por US$ 10 por mês. Todas as ferramentas do JobRise continuam grátis.