Let tests set the target

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

Temario del curso

Esta lección aún no está en tu idioma, así que aquí la tienes en inglés.

Prueba rápida

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.

El resto de esta lección es parte de Learn Pro

El primer módulo de cada curso es gratis. Learn Pro abre todas las lecciones de todos los cursos por US$10 al mes. Todas las herramientas de JobRise siguen siendo gratis.