question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add test.each() to support BDD

See original GitHub issue

This will help to support usage such as:

test.beforeEach(t => {
  t.context.game = new Game()
})

test.each(
[
  { c1: 1, c2: 2, dir: 'west' },
  { c1: 2, c2: 3, dir: 'south' },
  { c1: 3, c2: 4, dir: 'east' },
  { c1: 4, c2: 5, dir: 'north' }
], t => {
  const { game, c1, c2, dir } = t.context
  game.createAndConnectCaverns(c1, c2, dir)
  const p = game.createPlayerIn(c1)
  p.move(dir)
  t.is(p.location, c2)
})

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
novemberborncommented, Mar 5, 2017

Interesting. This is currently possible using macros:

const playerIsAtLocation = (t, c1, c2, dir) => {
  const { game } = t.context
  const p = game.createPlayerIn(c1)
  p.move(dir)
  t.is(p.location, c2)
}

for (const {c1, c2, dir} of [
  { c1: 1, c2: 2, dir: 'west' },
  { c1: 2, c2: 3, dir: 'south' },
  { c1: 3, c2: 4, dir: 'east' },
  { c1: 4, c2: 5, dir: 'north' }
]) {
  test(playerIsAtLocation, c1, c2, dir)
}

There’s something nice about your test.each() suggestion but I’m not sure it’s worth the maintenance cost.

1reaction
selenium-testercommented, Mar 16, 2017

Apologies for joining a dead thread; I came looking through the issues for any other discussions about parameterized/data-driven test support in Ava. I found lots of discussion in various tickets, but this seemed the most recent and most directly related to my search so I wanted to add an extra voice to the conversation.

The current macro capability is great, but I do agree it would be even nicer if we could just insert parameters into the test function directly as @unional described. I’ve seen several examples of something similar done for Mocha to simplify its dynamic tests:

https://github.com/mikejsdev/mocha-param

And for QUnit:

https://github.com/AStepaniuk/qunit-parameterize

And another more generic library for multiple test frameworks:

https://github.com/lawrencec/Unroll/blob/master/examples/ava/ava-example.js

And one going in a different direction to emulate TestNG decorators:

https://github.com/alsatian-test/alsatian

It’s definitely a common use case for easier test design. As you said, you’ve provided other ways to accomplish this so maybe we don’t strictly need it, but it would be a very nice to have.

In any event, thank you again for all the great work done on Ava.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parameterize BDD Tests | TestComplete Documentation
In BDD tests, you parameterize test steps, not scenarios or features. That is, you set parameters for the Given , When , and...
Read more >
BDD And Cucumber Tutorial With Examples
This In-Depth Cucumber Tutorial Discusses BDD And its Benefits, Cucumber Framework, Environmental Settings, Test Script Creation, ...
Read more >
Writing BDD Test Scenarios - Department of Product
A BDD scenario is a written description of your product's behavior from one or more users' perspectives to reduce the cost of translation....
Read more >
Behavior Driven Development (BDD) and Functional Testing
Functional tests on the other hand: Take longer to run, because they must test the system end-to-end, integrating with all the various parts...
Read more >
Test setup and teardown in Cucumber and Serenity BDD
Background steps are run before each scenario, including each example, so sometimes the test code might need to check whether a particular setup ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found