Add test.each() to support BDD
See original GitHub issueThis 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:
- Created 7 years ago
- Reactions:2
- Comments:10 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Interesting. This is currently possible using macros:
There’s something nice about your
test.each()
suggestion but I’m not sure it’s worth the maintenance cost.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.