Skip to main content

covertable

npm versionCIcodecovGitHub stars

covertable is a powerful tool for generating pairwise (and N-wise) combinations of input factors, designed for both Node.js and browser environments. It makes it easy to create comprehensive test cases that cover all factor interactions while keeping the number of test cases minimal.

What is Pairwise Testing?

Pairwise testing is a combinatorial testing technique that generates test cases covering all possible pairs of input parameters. Instead of testing every combination (which can be enormous), pairwise testing ensures that every pair of factor values appears in at least one test case, dramatically reducing the number of required tests while maintaining high defect detection rates.

Installation

npm install covertable --save

Quick Start

Array format

Pass an array of factor arrays to get results as arrays:

import { make } from "covertable";

const machine = ["iPhone", "Pixel", "XPERIA", "ZenFone", "Galaxy"];
const os = ["iOS", "Android"];
const browser = ["FireFox", "Chrome", "Safari"];

const rows = make([machine, os, browser]);
console.log(rows);

Output:

[
[ 'Pixel', 'iOS', 'Chrome' ],
[ 'ZenFone', 'iOS', 'FireFox' ],
[ 'Pixel', 'Android', 'Safari' ],
[ 'Galaxy', 'Android', 'Chrome' ],
[ 'XPERIA', 'Android', 'FireFox' ],
[ 'Pixel', 'iOS', 'FireFox' ],
[ 'iPhone', 'iOS', 'Safari' ],
[ 'Galaxy', 'iOS', 'Safari' ],
[ 'XPERIA', 'iOS', 'Chrome' ],
[ 'ZenFone', 'Android', 'Chrome' ],
[ 'Galaxy', 'iOS', 'FireFox' ],
[ 'iPhone', 'Android', 'Chrome' ],
[ 'iPhone', 'iOS', 'FireFox' ],
[ 'ZenFone', 'iOS', 'Safari' ],
[ 'XPERIA', 'iOS', 'Safari' ]
]

Object format

Pass an object of named factors to get results as objects:

import { make } from "covertable";

const rows = make({
machine: ["iPhone", "Pixel", "XPERIA", "ZenFone", "Galaxy"],
os: ["iOS", "Android"],
browser: ["FireFox", "Chrome", "Safari"],
});

console.log(rows);
// [
// { machine: 'Pixel', os: 'iOS', browser: 'Chrome' },
// { machine: 'ZenFone', os: 'iOS', browser: 'FireFox' },
// ...
// ]
info

When factors are given as an object, each result row will also be an object with the same keys.

Controller and Statistics

The make function is a convenient shortcut. For access to generation statistics, use Controller directly:

import { Controller } from "covertable";

const factors = { machine, os, browser };
const ctrl = new Controller(factors, { constraints: [...] });
const rows = ctrl.make();

console.log(ctrl.stats);
// {
// totalPairs: 30, // all pairs before pruning
// prunedPairs: 4, // removed by constraint propagation
// coveredPairs: 26, // pairs covered in output rows
// progress: 1, // coverage ratio (1 = 100%)
// rowCount: 8, // number of generated rows
// uncoveredPairs: [], // pairs that couldn't be covered
// completions: { ... } // values filled by backtracking
// }

See Constraint Logic for full details on each field.

Async Generation

Use makeAsync to generate rows one at a time via a generator:

import { makeAsync } from "covertable";

const machine = ["iPhone", "Pixel", "XPERIA", "ZenFone", "Galaxy"];
const os = ["iOS", "Android"];
const browser = ["FireFox", "Chrome", "Safari"];

for (const row of makeAsync([machine, os, browser])) {
console.log(row);
}

Requirements

ES2015 or later. The following features are used:

Next Steps

  • Learn about Advanced Usage including constraints, sorters, criteria, sub-models, and weights
  • Use the PictModel to parse and run full PICT-format models (parameters + constraints + sub-models + invalid values + weights)
  • Try the Compatible PICT tool
  • Check the History for release notes and Migration Guide
Migrating from v2

v3 introduces breaking changes including renamed options, declarative constraints replacing preFilter/postFilter, and a new PictModel class. See the Migration Guide for full details.