Generate testcases by simple but highly customizable rules.
npm i testcase-gen
For example: sum of two numbers.
const { Generator } = require("testcase-gen");
const rules = [
{
name: "2 Positives (1 ~ 99999)",
regex: /[1-9]\d{0,4} [1-9]\d{0,4}/,
repeat: 20,
},
{
name: "2 Negatives (-1 ~ -99999)",
regex: /-[1-9]\d{0,4} -[1-9]\d{0,4}/,
repeat: 20,
},
{
name: "1 Zero, 1 Positive (1 ~ 100000)",
generator: () => `0 ${1 + Math.floor(Math.random() * 100000)}`,
repeat: 10,
},
{
name: "1 Zero, 1 Negative (-1 ~ -100000)",
generator: function () {
return `0 -${1 + Math.floor(Math.random() * 100000)}`;
},
repeat: 10,
},
{
name: "2 Zero",
text: "0 0",
},
];
const generator = new Generator(rules);
console.log(generator.gen());
Each rule must have one of the following properties: generator
or regex
or text
.
And the following properties are optional: name
, repeat
.
There are 3 ways to generate testcases: Generator Function, Regex and Text.
The order of rule applying is:
- Generator Function
- Regex
- Text
I recommand you to use Generator Function because it is more flexible.
npm i -g testcase-gen
testcase-gen --recipe [recipe] --output [output] --mode [mode]
--recipe (-r): Recipe JS File Path.
--output (-o): Output File Path.
--mode (-m): Generate Mode. "simple" or "normal".
--version (-V) or (-v): Show version.