Testing (Pruebas)

Paulo7 de enero de 2026

Definición

Proceso de evaluar software para identificar defectos y asegurar que funciona como se espera.

Descripción

Incluye pruebas unitarias, de integración, E2E y funcionales. Fundamental para software de calidad.

Ejemplo

JavaScript
// Pirámide de Testing

//         /\
//        /E2E\        (Playwright, Cypress)
//       /──────\
//      /Integración\  (SuperTest, Testing Library)
//     /──────────────\
//    /    Unitarias    \ (Jest, Vitest)
//   /────────────────────\

// Test Unitario (función aislada)
test('formatea precio correctamente', () => {
  expect(formatearPrecio(1234.5)).toBe('$1,234.50');
});

// Test de Integración (varios componentes juntos)
test('API crea usuario correctamente', async () => {
  const res = await request(app)
    .post('/api/usuarios')
    .send({ nombre: 'Test', email: 'test@test.com' });

  expect(res.status).toBe(201);
  expect(res.body.id).toBeDefined();
});

// Test E2E (flujo completo desde UI)
test('usuario puede hacer login', async ({ page }) => {
  await page.goto('/login');
  await page.fill('[name=email]', 'test@test.com');
  await page.fill('[name=password]', 'password');
  await page.click('button[type=submit]');
  await expect(page).toHaveURL('/dashboard');
});

// Coverage
// npm run test -- --coverage
// Objetivo: >80% de cobertura