Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringSpec test cases with multiline names broken #1441

Closed
neelkamath opened this issue May 16, 2020 · 6 comments · Fixed by #1444
Closed

StringSpec test cases with multiline names broken #1441

neelkamath opened this issue May 16, 2020 · 6 comments · Fixed by #1444
Assignees
Labels
bug 🐛 Issues that report a problem or error in the code. framework 🏗️ Pertains to the core structure and components of the Kotest framework.
Milestone

Comments

@neelkamath
Copy link

Bugs

I think I have found two bugs with StringSpecs. I'm unsure whether other testing styles are affected as well.

Environment

Here's my environment. I'm unsure whether other environments are affected.

  • Kotlin/JVM 1.3.72
  • Kotest 4.0.5
  • Gradle 6.4

Bug 1: Test Failures

Consider this psuedocode.

class TestSuite : StringSpec({
    """
    test
    case
    1
    """ {
        // test
    }

    """
    test
    case
    2
    """ {
        // test
    }

    "test case 3" {
        // test 
    }
})

If I run the entire suite, and the first two test cases fail, then the error message used for one of the cases is used as the error message for the other case as well. Similarly, if only one of the first two cases fail, both fail with the error message of the failed case.

I guess this happens even if there's more than one test case with a multiline name.

Bug 2: Focusing

Focusing (prepending the test case's name with f:) doesn't work for test cases with multiline names. In essence, every test case runs even if I focus a test case with a multiline name.

I guess the same holds true for bangs (prepending the test case's name with !).

@ashishkujoy
Copy link
Contributor

ashishkujoy commented May 16, 2020

@neelkamath For the first problem if you observe carefully the report mentions 3 test failure instead of 2, with two of them with same stacktrace(and failure message) but only one of them will have actual test name and other will executionError as test name. This is a known problem with reporting in kotest #1330
Screenshot 2020-05-16 21 30 36

@ashishkujoy
Copy link
Contributor

Two the second problem
instead of this

"""
f:test
case
2""" {

}

Use

"""f:
test
case
2"""
``` {
}

@sksamuel sksamuel added bug 🐛 Issues that report a problem or error in the code. framework 🏗️ Pertains to the core structure and components of the Kotest framework. labels May 16, 2020
@sksamuel
Copy link
Member

sksamuel commented May 16, 2020 via email

@neelkamath
Copy link
Author

@ashishkujoy

Regarding Bug 1

Note: When I refer to "test case", I mean "test case with a multiline name".

I tried to reproduce bug 1 today with simpler code.

When one test case is supposed to pass, and another is supposed to fail, only one fails. This is not a bug.

However, bug 1 still exists, in the other scenario I mentioned. Consider the following code.

import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe

class MyTest : StringSpec({
    """
    test
    case
    1
    """ { 1 shouldBe 2 }

    """
    test
    case 
    2
    """ { true shouldBe false }
})

Both tests are supposed to fail, and they both do. However, the test report shows test case 1's failure for test case 2's failure as well. Please unzip the attached folder and open index.html in your browser to see the Gradle report (I'm unsure whether this is a Gradle bug).

Test Report.zip

Regarding Bug 2

Your focusing technique works, and makes sense. It didn't occur to me that whitespace would've affected it, especially since Gradle replaces multiline test case names with single spaces. It might help to add this to the focus (and bang) docs.

@sksamuel
Copy link
Member

sksamuel commented May 17, 2020 via email

@sksamuel
Copy link
Member

Fix will be included in 4.0.6 and 4.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Issues that report a problem or error in the code. framework 🏗️ Pertains to the core structure and components of the Kotest framework.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants