kotest / kotest-intellij-plugin

The official Kotest plugin for Intellij and Android Studio
Apache License 2.0
179 stars 25 forks source link

Intellij does not recognize dynamic strings #228

Closed edeesis closed 1 year ago

edeesis commented 2 years ago

When defining a test name (in my case we're using DescribeSpec), we're unable to run the blocks with dynamic strings, causing us to have to run the entire test class.

class Test : DescribeSpec({
  describe(123.toString()) {
    it("test") {
      "str" shouldBe "str"
    }
  }
})

You lose gutter icons as well. You still have it on it test level but if you try to use that one, it'll not find the test.

image

Kantis commented 2 years ago

I don't think there's much we can do about this. How would this case work, for instance?

class Test : DescribeSpec({
  describe(Random.nextLong().toString()) {
    it("test") {
      "str" shouldBe "str"
    }
  }
})

The gutter icons generate a run configuration with a test-filter matching the name of the test.. I the name of the test is not a String literal, we can't know for sure what it'll be.

sksamuel commented 1 year ago

Yep, nothing we can do here. The best we could do is add a warning / highlight that says "dynamic test names cannot be run automatically" ?

edeesis commented 1 year ago

What if the string was a const in an object definition? Not sure if that changes anything.

edeesis commented 1 year ago

If it helps, my use case is to put function references directly in the describe blocks for refactor-safety:

describe(LineItemFinder::all.name) {

Could the describe function take a function reference?

sksamuel commented 1 year ago

It could work with anything that is statically resolvable in the PSI representation that Intellij uses.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.