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.

When using Data Driven Testing, separate rows are not treated as separate tests

See original GitHub issue

Hi, 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
wrobliskocommented, Oct 30, 2018

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.

0reactions
crazyk2commented, Mar 23, 2020

Yes it works. Thank you.

Read more comments on GitHub >

github_iconTop 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 >

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