When using Data Driven Testing, separate rows are not treated as separate tests
See original GitHub issueHi, I found out that this is probably not working as expected. When using Data Driven Testing, methods like before/afterTest are not called for every row of each test.
import io.kotlintest.Description
import io.kotlintest.data.forall
import io.kotlintest.shouldBe
import io.kotlintest.specs.StringSpec
import io.kotlintest.tables.row
class TestSpec : StringSpec() {
var myMock = 10
init {
"myMock should be equal 10" {
forall(
row("first test"), row("second test")
) { sum ->
//expect
myMock shouldBe 10
//side effect
myMock = 11
}
}
}
override fun beforeTest(description: Description) {
//like resetting mocks between tests
myMock = 10
}
}
The same story is with overriding method isInstancePerTest. I would expect that new instance of class will be created for every row for every test.
The main usecase for this is resetting mocks after every test.
I hope that this is a bug, Maciej
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:9 (7 by maintainers)
Top Results From Across the Web
When using Data Driven Testing, separate rows are not ...
When using Data Driven Testing, methods like before/afterTest are not called for every row of each test. ... The same story is with...
Read more >All you need to know about Data-Driven Testing - Testsigma
DDT separates test logic (script) from test data (input values), making both easier to create, edit, use, and manage at scale. Therefore, DDT...
Read more >Java TestNG with Data Driven Testing Across Multiple Tests
You can keep dataprovider in a separate class and then annotate your tests with the dataprovider. You can specify it using dataProviderClass.
Read more >Creating Data-Driven Tests - Micro Focus
Check the Each data row is a single test check box to have each row in your data set considered to be a...
Read more >What is Data Driven Testing? Learn to create Framework
To create an individual test for each data set is a lengthy and time-consuming process. Data Driven Testing framework resolves this issue by...
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 FreeTop 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
Top GitHub Comments
Thanks for replies. I understand the cause of the problem, but from user perspective every row should be treated as separate test. Some frameworks (e.g. Spock @Unroll) even create separate test entries for each data row.
It would be great if this would work like this in Kotlin Test. Otherwise using mocks is really error-prone.
Yes it works. Thank you.