Back to Blog
Best Practices

5 Best Practices for Writing Natural Language Test Cases

Write test cases that the AI executes reliably every time. Learn the patterns that make natural language tests specific, maintainable, and effective.

Qualigate TeamJanuary 15, 20266 min read

Writing Tests the AI Can Ace

Natural language testing removes the need for code, but it does not remove the need for clarity. A well-written test step gives the AI exactly enough context to choose the right element and verify the right outcome. A vague step forces the AI to guess---and guessing leads to flaky results.

Here are five practices that consistently produce reliable, maintainable test cases in Qualigate.

1. Use Action Verbs and Be Direct

Every step should start with a clear verb that tells the AI what to do.

Weak:

text
The search bar should have "running shoes" in it

Strong:

text
Type "running shoes" into the search bar and press Enter

The strong version has an explicit action (type), a specific value ("running shoes"), a target (search bar), and a follow-up action (press Enter). The AI can execute this without ambiguity.

Recommended verbs: Navigate, Click, Type, Select, Scroll, Verify, Wait, Press, Hover, Clear.

2. Include Explicit Assertions

A test without assertions is just a demo. Always end critical sections with a "Verify" step that tells the AI what success looks like.

text
1. Click the "Add to Cart" button
2. Verify that the cart badge shows "1"
3. Verify that a success toast message appears

Good assertion patterns include:

  • Verify that [element] is visible -- checks existence

  • Verify that [element] contains "text" -- checks content

  • Verify that the URL contains "/dashboard" -- checks navigation

  • Verify that no error message is displayed -- checks absence


Without assertions, a test can silently pass even when the application is broken.

3. Handle Authentication Flows Properly

Many tests require a logged-in user. Rather than repeating login steps in every test, use Qualigate's stored credentials feature:

text
1. Navigate to the login page
2. Enter the stored email credential in the email field
3. Enter the stored password credential in the password field
4. Click "Sign In"
5. Verify that the dashboard loads

You can store credentials securely in your project settings. The AI will retrieve them at runtime. This keeps sensitive data out of your test steps and lets you rotate credentials without editing every test case.

Pro tip: If your app uses multi-factor authentication, include a step like "Enter the MFA code from the authenticator app" and configure email testing to capture verification codes.

4. Write Steps That Survive UI Changes

The AI finds elements by visual context, text content, and semantic role---not by CSS selector. Take advantage of this by referencing what the user sees rather than implementation details.

Brittle:

text
Click the element with class "btn-primary-lg"

Resilient:

text
Click the "Submit Order" button

The second version works whether the button is styled with Tailwind, Bootstrap, or custom CSS. The AI matches on visible text and ARIA role, which are far more stable than class names.

Similarly, prefer relative language:

  • "Click the first product in the list" over "Click the element at index 0"

  • "Select 'Medium' from the size dropdown" over "Select the third option"


5. Break Complex Flows into Logical Sections

Long tests with 30+ steps are harder to debug when they fail. Group related actions and separate sections with a comment line:

text
1. Navigate to the product catalog
2. Search for "wireless headphones"
3. Click on the first search result
4. Verify that the product detail page loads

5. Select "Black" from the color options
6. Click "Add to Cart"
7. Verify that the cart count increases to 1

8. Click the cart icon
9. Click "Proceed to Checkout"
10. Verify that the checkout page loads with the correct item

Each group tests one logical concept: finding a product, adding to cart, and starting checkout. If step 6 fails, you know the issue is with the add-to-cart interaction, not with search or checkout.

For truly long workflows, consider splitting them into separate test cases grouped in a test suite. This gives you parallel execution and more granular pass/fail reporting.

Putting It All Together

A well-structured test case combines all five practices:

text
1. Navigate to https://myshop.com
2. Type "winter jacket" in the search field and press Enter
3. Verify that search results appear
4. Click the first product in the results
5. Verify that the product detail page loads
6. Select "Large" from the size dropdown
7. Click "Add to Cart"
8. Verify that a confirmation message appears
9. Click the cart icon in the header
10. Verify that the cart contains 1 item with the correct product name

Direct verbs, explicit assertions, UI-visible references, and logical grouping. The AI will execute this reliably across deployments, browsers, and design changes.


Start writing better tests today. Try Qualigate free and experience the difference clarity makes.

Tags

best-practicestest-casestips

Ready to Transform Your Testing?

Experience AI-powered testing that writes itself. Start free and see results in minutes.

Start Free Trial