Make every test fail once

Module 1 : Test with AI, and prove every test works

Plan du cours

Cette leçon n'est pas encore dans votre langue, la voici donc en anglais.

Trouvez les erreurs

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 sur 1 trouvées

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.

Complétez les trous

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

Vos étapes, environ 2 minutes

0 sur 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

Exercices

Question 1 sur 2

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

Tuteur IA

Posez vos questions sur cette leçon et faites-vous guider dans l'exercice « Essayez ». Le tuteur fait partie de Learn Pro.

Voir Learn Pro