All Projects β†’ ehmicky β†’ Test Each

ehmicky / Test Each

Licence: apache-2.0
πŸ€– Repeat tests. Repeat tests. Repeat tests.

Programming Languages

javascript
184084 projects - #8 most used programming language
es6
455 projects

Projects that are alternatives of or similar to Test Each

clusterfuzzlite
ClusterFuzzLite - Simple continuous fuzzing that runs in CI.
Stars: ✭ 315 (+253.93%)
Mutual labels:  continuous-integration, fuzzing, fuzz-testing
arduino-ci-script
Bash script for continuous integration of Arduino projects
Stars: ✭ 25 (-71.91%)
Mutual labels:  continuous-integration, test, test-automation
Ocaramba
C# Framework to automate tests using Selenium WebDriver
Stars: ✭ 234 (+162.92%)
Mutual labels:  data-driven, test, test-automation
Log Process Errors
Show some ❀️ to Node.js process errors
Stars: ✭ 424 (+376.4%)
Mutual labels:  library, test, code-quality
Example Go
Go Fuzzit Example
Stars: ✭ 39 (-56.18%)
Mutual labels:  fuzzing, fuzz-testing
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+39388.76%)
Mutual labels:  test, test-automation
Afl.rs
πŸ‡ Fuzzing Rust code with American Fuzzy Lop
Stars: ✭ 1,013 (+1038.2%)
Mutual labels:  fuzzing, fuzz-testing
Burpsuite Collections
BurpSuiteζ”Άι›†οΌšεŒ…ζ‹¬δΈι™δΊŽ Burp ζ–‡η« γ€η ΄θ§£η‰ˆγ€ζ’δ»Ά(非BApp Store)γ€ζ±‰εŒ–η­‰η›Έε…³ζ•™η¨‹οΌŒζ¬’θΏŽζ·»η –εŠ η“¦---burpsuite-pro burpsuite-extender burpsuite cracked-version hackbar hacktools fuzzing fuzz-testing burp-plugin burp-extensions bapp-store brute-force-attacks brute-force-passwords waf sqlmap jar
Stars: ✭ 1,081 (+1114.61%)
Mutual labels:  fuzzing, fuzz-testing
Cargo Fuzz
Command line helpers for fuzzing
Stars: ✭ 725 (+714.61%)
Mutual labels:  fuzzing, fuzz-testing
Fluenttc
🌊 πŸ‘¬ 🏒 Integrate with TeamCity fluently
Stars: ✭ 42 (-52.81%)
Mutual labels:  library, continuous-integration
Noexception
Java library for handling exceptions in concise, unified, and architecturally clean way.
Stars: ✭ 56 (-37.08%)
Mutual labels:  library, functional-programming
Pointfreeco
🎬 The source for www.pointfree.co, a video series on functional programming and the Swift programming language.
Stars: ✭ 782 (+778.65%)
Mutual labels:  functional-programming, snapshot-testing
Fuzzingpaper
Recent Fuzzing Paper
Stars: ✭ 773 (+768.54%)
Mutual labels:  fuzzing, fuzz-testing
Redash
Tiny functional programming suite for JavaScript.
Stars: ✭ 40 (-55.06%)
Mutual labels:  library, functional-programming
Oss Fuzz
OSS-Fuzz - continuous fuzzing for open source software.
Stars: ✭ 6,937 (+7694.38%)
Mutual labels:  fuzzing, fuzz-testing
Powerslim
Fitnesse Slim implementation in PowerShell. PowerSlim makes it possible to use PowerShell in the acceptance testing
Stars: ✭ 49 (-44.94%)
Mutual labels:  test, test-automation
Cross Platform Node Guide
πŸ“— How to write cross-platform Node.js code
Stars: ✭ 1,161 (+1204.49%)
Mutual labels:  continuous-integration, code-quality
Elmyr
A utility to make Kotlin/Java tests random yet reproducible
Stars: ✭ 68 (-23.6%)
Mutual labels:  test, fuzzing
Gremlins.js
Monkey testing library for web apps and Node.js
Stars: ✭ 8,790 (+9776.4%)
Mutual labels:  test, fuzz-testing
Testcafe
A Node.js tool to automate end-to-end web testing.
Stars: ✭ 9,176 (+10210.11%)
Mutual labels:  test, test-automation

Codecov Travis Node Gitter Twitter Medium

πŸ€– Repeat tests. Repeat tests. Repeat tests.

Repeats tests using different inputs (Data-Driven Testing):

  • test runner independent: works with your current setup
  • generates test titles that are descriptive, unique, for any JavaScript type (not just JSON)
  • loops over every possible combination of inputs (cartesian product)
  • can use random functions (fuzz testing)
  • snapshot testing friendly

Example

// The examples use Ava but any test runner works (Jest, Mocha, Jasmine, etc.)
const test = require('ava')
const { each } = require('test-each')

// The code we are testing
const multiply = require('./multiply.js')

// Repeat test using different inputs and expected outputs
each(
  [
    { first: 2, second: 2, output: 4 },
    { first: 3, second: 3, output: 9 },
  ],
  ({ title }, { first, second, output }) => {
    // Test titles will be:
    //    should multiply | {"first": 2, "second": 2, "output": 4}
    //    should multiply | {"first": 3, "second": 3, "output": 9}
    test(`should multiply | ${title}`, t => {
      t.is(multiply(first, second), output)
    })
  },
)

// Snapshot testing. The `output` is automatically set on the first run,
// then re-used in the next runs.
each(
  [
    { first: 2, second: 2 },
    { first: 3, second: 3 },
  ],
  ({ title }, { first, second }) => {
    test(`should multiply outputs | ${title}`, t => {
      t.snapshot(multiply(first, second))
    })
  },
)

// Cartesian product.
// Run this test 4 times using every possible combination of inputs
each([0.5, 10], [2.5, 5], ({ title }, first, second) => {
  test(`should mix integers and floats | ${title}`, t => {
    t.is(typeof multiply(first, second), 'number')
  })
})

// Fuzz testing. Run this test 1000 times using different numbers.
each(1000, Math.random, ({ title }, index, randomNumber) => {
  test(`should correctly multiply floats | ${title}`, t => {
    t.is(multiply(randomNumber, 1), randomNumber)
  })
})

Demo

You can try this library:

Install

npm install -D test-each

Usage

const { each } = require('test-each')

const inputs = [
  ['red', 'blue'],
  [0, 5, 50],
]
each(...inputs, function callback(info, color, number) {})

Fires callback once for each possible combination of inputs.

Each input can be an array, a function or an integer.

A common use case for callback is to define tests (using any test runner).

info is an object whose properties can be used to generate test titles.

Test titles

Each combination of parameters is stringified as a title available in the callback's first argument.

Titles should be included in test titles to make them descriptive and unique.

Long titles are truncated. An incrementing counter is appended to duplicates.

Any JavaScript type is stringified, not just JSON.

You can customize titles either by:

each([{ color: 'red' }, { color: 'blue' }], ({ title }, param) => {
  // Test titles will be:
  //    should test color | {"color": "red"}
  //    should test color | {"color": "blue"}
  test(`should test color | ${title}`, () => {})
})

// Plain objects can override this using a `title` property
each(
  [
    { color: 'red', title: 'Red' },
    { color: 'blue', title: 'Blue' },
  ],
  ({ title }, param) => {
    // Test titles will be:
    //    should test color | Red
    //    should test color | Blue
    test(`should test color | ${title}`, () => {})
  },
)

// The `info` argument can be used for dynamic titles
each([{ color: 'red' }, { color: 'blue' }], (info, param) => {
  // Test titles will be:
  //    should test color | 0 red
  //    should test color | 1 blue
  test(`should test color | ${info.index} ${param.color}`, () => {})
})

Cartesian product

If several inputs are specified, their cartesian product is used.

// Run callback five times: a -> b -> c -> d -> e
each(['a', 'b', 'c', 'd', 'e'], (info, param) => {})

// Run callback six times: a c -> a d -> a e -> b c -> b d -> b e
each(['a', 'b'], ['c', 'd', 'e'], (info, param, otherParam) => {})

// Nested arrays are not iterated.
// Run callback only twice: ['a', 'b'] -> ['c', 'd', 'e']
each(
  [
    ['a', 'b'],
    ['c', 'd', 'e'],
  ],
  (info, param) => {},
)

Input functions

If a function is used instead of an array, each iteration fires it and uses its return value instead. The function is called with the same arguments as the callback.

The generated values are included in test titles.

// Run callback with a different random number each time
each(['red', 'green', 'blue'], Math.random, (info, color, randomNumber) => {})

// Input functions are called with the same arguments as the callback
each(
  ['02', '15', '30'],
  ['January', 'February', 'March'],
  ['1980', '1981'],
  (info, day, month, year) => `${day}/${month}/${year}`,
  (info, day, month, year, date) => {},
)

Fuzz testing

Integers can be used instead of arrays to multiply the number of iterations.

This enables fuzz testing when combined with input functions and libraries like faker.js, chance.js or json-schema-faker.

const faker = require('faker')

// Run callback 1000 times with a random UUID and color each time
each(
  1000,
  faker.random.uuid,
  faker.random.arrayElement(['green', 'red', 'blue']),
  (info, randomUuid, randomColor) => {},
)

// `info.index` can be used as a seed for reproducible randomness.
// The following series of 1000 UUIDs will remain the same across executions.
each(
  1000,
  ({ index }) => faker.seed(index) && faker.random.uuid(),
  (info, randomUuid) => {},
)

Snapshot testing

This library works well with snapshot testing.

Any library can be used (snap-shot-it, Ava snapshots, Jest snapshots, Node TAP snapshots, etc.).

// The `output` is automatically set on the first run,
// then re-used in the next runs.
each(
  [
    { first: 2, second: 2 },
    { first: 3, second: 3 },
  ],
  ({ title }, { first, second }) => {
    test(`should multiply outputs | ${title}`, t => {
      t.snapshot(multiply(first, second))
    })
  },
)

Side effects

If callback's parameters are directly modified, they should be copied to prevent side effects for the next iterations.

each(
  ['green', 'red', 'blue'],
  [{ active: true }, { active: false }],
  (info, color, param) => {
    // This should not be done, as the objects are re-used in several iterations
    param.active = false

    // But this is safe since it's a copy
    const newParam = { ...param }
    newParam.active = false
  },
)

Iterables

iterable() can be used to iterate over each combination instead of providing a callback.

const { iterable } = require('test-each')

const combinations = iterable(
  ['green', 'red', 'blue'],
  [{ active: true }, { active: false }],
)

for (const [{ title }, color, param] of combinations) {
  test(`should test color | ${title}`, () => {})
}

The return value is an Iterable. This can be converted to an array with the spread operator.

const array = [...combinations]

array.forEach(([{ title }, color, param]) => {
  test(`should test color | ${title}`, () => {})
})

API

each(...inputs, callback)

inputs: Array | function | integer (one or several)
callback: function(info, ...params)

Fires callback with each combination of params.

iterable(...inputs)

inputs: Array | function | integer (one or several)
Return value: Iterable<[info, ...params]>

Returns an Iterable looping through each combination of params.

info

Type: object

info.title

Type: string

Like params but stringified. Should be used in test titles.

info.titles

Type: string[]

Like info.title but for each param.

info.index

Type: integer

Incremented on each iteration. Starts at 0.

info.indexes

Type: integer[]

Index of each params inside each initial input.

params

Type: any (one or several)

Combination of inputs for the current iteration.

Support

If you found a bug or would like a new feature, don't hesitate to submit an issue on GitHub.

For other questions, feel free to chat with us on Gitter.

Everyone is welcome regardless of personal background. We enforce a Code of conduct in order to promote a positive and inclusive environment.

Contributing

This project was made with ❀️. The simplest way to give back is by starring and sharing it online.

If the documentation is unclear or has a typo, please click on the page's Edit button (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check our guidelines. Pull requests are welcome!

ehmicky
ehmicky

πŸ’» 🎨 πŸ€” πŸ“–
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].