Make every test fail once

Módulo 1: Test with AI, and prove every test works

Conteúdo do curso

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

Encontre os erros

Guess first, no penalty. A $5 promo code should turn a $50 cart into $45. The code is broken and the total stays at $50, but this AI-written Playwright test still passes. Tap the line that lets it pass.

The test, line by line

0 de 1 encontrados

A test that never fails proves nothing

Playwright is a popular tool for automated browser tests. An assertion is the line in a test that checks a result. AI tools often write assertions that check something exists or is visible, instead of checking it's right. Those tests go green whether the feature works or not.

The habit that catches this takes one minute: before you trust a new test, make it fail on purpose.

  • Change the expected value in the test, such as $45.00 to $50.00, and run it. It should fail.
  • Or break the feature in a local copy, and run it. It should fail.

If it still passes, the assertion isn't checking anything. Fix the assertion, then run the same check again.

Playwright's assertion docs list matchers such as toHaveText, which checks an element's text, and toBeVisible, which only checks it's visible.

A worked example

Fixed test:
  await expect(page.getByTestId('cart-total')).toHaveText('$45.00');

Fail-once check:
  Changed '$45.00' to '$50.00'      -> test failed, as it should
  Changed it back                    -> test passed
Result: the test checks the total for real. Keep it.

Preencha as lacunas

Fill the gaps.

Fail-once check

I assert the . Then I change the expected value and run the test: it should . If it still passes, .

Try it

Seus passos, cerca de 2 minutos

0 de 1
  1. 1.Take one AI-written test from your suite. Change its expected value, run it, and note whether it failed. Add "make it fail once" to your AI test kit.2 min

Exercícios

Pergunta 1 de 2

Which assertion proves a $5 promo code works on a $50 cart?

Tutor de IA

Tire dúvidas sobre esta aula e tenha ajuda na tarefa do “Experimente”. O tutor faz parte do Learn Pro.

Ver o Learn Pro