Data-Driven Testing

Test Data

// Definition

Running the same test logic against many input/output combinations, typically loaded from a CSV, JSON file, or database. Separates test data from test code so you can scale coverage without duplicating logic.

// Code Example

CypressSame logic, many inputs
TypeScript
const cases = [
  { input: 'user@example.com', valid: true },
  { input: 'no-at.com',        valid: false },
  { input: '',                 valid: false },
];

cases.forEach(({ input, valid }) => {
  it(`validates "${input}" → ${valid}`, () => {
    cy.visit('/signup');
    cy.get('[data-testid=email]').type(input || ' ');
    cy.get('[data-testid=submit]').click();
    cy.get('[data-testid=email-error]').should(
      valid ? 'not.exist' : 'be.visible',
    );
  });
});

// Related terms

Learn more · TestNG

Chapter 3 · Lesson 1: @DataProvider Basics