From 9cd1e4c9e5ec46e4df4d96b702320b3e1aae8f00 Mon Sep 17 00:00:00 2001 From: Carsten Klein Date: Thu, 4 Apr 2019 18:42:41 +0200 Subject: [PATCH] feature #18: guide/parametrised tests section --- pages/guide/parametrised_tests.md | 170 ++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 pages/guide/parametrised_tests.md diff --git a/pages/guide/parametrised_tests.md b/pages/guide/parametrised_tests.md new file mode 100644 index 0000000..62c6062 --- /dev/null +++ b/pages/guide/parametrised_tests.md @@ -0,0 +1,170 @@ +--- +layout: guide +section: guide +role: page +order: 70 +toc: true +title: Parametrised Tests +label: Parametrised Tests +description: | + Parametrised Tests +--- + +{:.toc} +## Parametrised Tests + +{% highlight TypeScript linenos %} +import { suite, params } from '@testdeck/mocha'; + +@suite +class Suite { + + @params({ arg1: 'foo', arg2: 'bar' }) + @params({ arg1: 'bar', arg2: 'foo' }, 'custom test name') + test({ arg1, arg2 }) { + } +} +{% endhighlight %} + +### Run Tests + +{% highlight shell %} +npm test + +... + + Suite + test + ✓ test 0 + ✓ custom test name + +... +{% endhighlight %} + + +{:.toc} +## Parametrised Test Naming {% include support-all.html %} + +{% highlight TypeScript linenos %} +import { suite, params } from '@testdeck/mocha'; + +@suite +class Suite { + + @params({ arg1: 'foo', arg2: 'bar' }, 'a custom test name') + @params({ arg1: 'bar', arg2: 'foo' }) + @params.naming(({ arg1, arg2 }) => `test foobar against ${arg1} and ${arg2}`) + test({ arg1, arg2 }) { + } +} +{% endhighlight %} + +### Run Tests + +{% highlight shell %} +npm test + +... + + Suite + test + ✓ a custom test name + ✓ test foobar against bar and foo + +... +{% endhighlight %} + + +{:.toc} +## Pending Parameter Sets {% include support-all.html %} + +{% highlight TypeScript linenos %} +import { suite, params } from '@testdeck/mocha'; + +@suite +class Suite { + + @params({ arg1: 'foo', arg2: 'bar' }) + @params.pending({ arg1: 'bar', arg2: 'foo' }, 'SUT does not yet support this') + "test foobar against parameters"({ arg1, arg2 }) { + } +} +{% endhighlight %} + +### Run Tests + +{% highlight shell %} +npm test + +... + + Suite + test foobar against parameters + ✓ test foobar against parameters 0 + - SUT does not yet support this + +... +{% endhighlight %} + + +{:.toc} +## Skipping Parameter Sets {% include support-all.html %} + +{% highlight TypeScript linenos %} +import { suite, params } from '@testdeck/mocha'; + +@suite +class Suite { + + @params({ arg1: 'foo', arg2: 'bar' }) + @params.skip({ arg1: 'bar', arg2: 'foo' }, 'test fails on this, no time fixing') + test({ arg1, arg2 }) { + } +} +{% endhighlight %} + +### Run Tests + +{% highlight shell %} +npm test + +... + + Suite + test + ✓ test 0 + - test fails on this, no time fixing + +... +{% endhighlight %} + + +{:.toc} +## Focused Parameter Set Testing {% include support-all.html %} + +{% highlight TypeScript linenos %} +import { suite, params } from '@testdeck/mocha'; + +@suite +class Suite { + + @params({ arg1: 'foo', arg2: 'bar' }) + @params.only({ arg1: 'bar', arg2: 'foo' }, 'should be fixed now...') + test({ arg1, arg2 }) { + } +} +{% endhighlight %} + +### Run Tests + +{% highlight shell %} +npm test + +... + + Suite + test + ✓ should be fixed now... + +... +{% endhighlight %}