kotest-gradle-plugin icon indicating copy to clipboard operation
kotest-gradle-plugin copied to clipboard

Add tests filter

Open sksamuel opened this issue 4 years ago • 15 comments

sksamuel avatar Sep 26 '20 20:09 sksamuel

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.

stale[bot] avatar Nov 26 '20 00:11 stale[bot]

@sksamuel similar to the tag request, a filter would be really helpful. the exclude / filter options on the test task only work for me if I use Junit but I really would prefer using this plugin.

rezammalik avatar Mar 25 '21 04:03 rezammalik

This is easy to do, but we need to consider what syntax to use.

Gradle style perhaps:

entire spec --tests a.b.SpecName

or specific test path

--tests a.b.SpecName mytest**

or

--include a.b.SpecName mytest** --exclude a.b.SpecName mytest**

sksamuel avatar Apr 14 '21 16:04 sksamuel

I prefer the gradle style commands with filtering by class name personally. A specific test would be super cool because then I don't have to do the f: thingy to focus for each test in code when I am debugging. The first one to run a specific spec is also helpful.

rezammalik avatar Apr 14 '21 16:04 rezammalik

Retaining this functionality would be nice if it is not too much work:

https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/TestFilter.html

rezammalik avatar Apr 14 '21 16:04 rezammalik

Yeah that's what I was thinking. The gradle one isn't great as it uses a ClassMethodFilter internally which assumes the test name is a method handle.

sksamuel avatar Apr 14 '21 16:04 sksamuel

Ah gotcha. The killer feature is the specific test within a spec.

How hard is it to do a line number run? Like in ruby they have this thing where you can call File:<line number> and it will run the containing test. Just a thought and maybe not even something thats possible

rezammalik avatar Apr 14 '21 16:04 rezammalik

Line number is possible, but I think the test path is sufficient

--include a.b.Spec full name of test here (or wilcard).

On Wed, 14 Apr 2021 at 11:32, Reza Malik @.***> wrote:

Ah gotcha. The killer feature is the specific test within a spec.

How hard is it to do a line number run? Like in ruby they have this thing where you can call File: and it will run the containing test. Just a thought and maybe not even something thats possible

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/kotest/kotest-gradle-plugin/issues/3#issuecomment-819654696, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGQHJ4XKZO5LJLT3ORLTIW7SNANCNFSM4R3DNLXQ .

sksamuel avatar Apr 14 '21 16:04 sksamuel

Agreed there

rezammalik avatar Apr 14 '21 16:04 rezammalik

@sksamuel Like we discussed, this would be a very needed enhancement when you get a chance to get to it.

rezammalik avatar Jun 14 '21 15:06 rezammalik

It will go into 5.0

On Mon, 14 Jun 2021 at 10:24, Reza Malik @.***> wrote:

@sksamuel https://github.com/sksamuel Like we discussed, this would be a very needed enhancement when you get a chance to get to it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/kotest/kotest-gradle-plugin/issues/3#issuecomment-860774188, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGVWCX4O3Y25D4H4JO3TSYNL7ANCNFSM4R3DNLXQ .

sksamuel avatar Jun 14 '21 15:06 sksamuel

Test filtering works well using the Kotest plugin for IntelliJ. The "Kotest" tool window uses the current editor view to show the opened spec class with a list of its test paths. You can use it to create a new Kotest run configuration which allows to configure "Test Path", "Spec Class", and "Package". It used these values and passes them to the kotest engine language entry point, e.g. io.kotest.engine.launcher.MainKt --package my.package.com --spec my.package.com.MySpec --testpath test path --reporter teamcity

It seems the Kotest Gradle plugin also uses this entry point but does not pass these arguments.

There is a guide page [1] that lists Kotest specific test filtering parameters -Dkotest.filter.specs and -Dkotest.filter.tests. I tested using these parameters but could not make them work. It's maybe caused when test forks the JVM and does not propagate the -D arguments passed to gradle to the test.

[1] https://kotest.io/docs/framework/conditional/conditional-tests-with-gradle.html

Update:

Filtering for package and spec class worked for me using ./gradlew test --tasks:

$ ./gradlew test --tests "my.package.com*"
$ ./gradlew test --tests "*MySpec"

However using plugins { id("io.kotest") version "0.3.8" } and Gradle 7.3.2 it will ignore my test filters and run all tests when I use the kotest gradle task, e.g. ./gradle kotest --tests "*MySpec".

Another update:

Argh, we still use Kotlin 1.5.30 and Kotest 4.6.4. Have to update to Kotlin 1.6.x and Kotest 5.x.x in the future.

hastebrot avatar Jan 28 '22 14:01 hastebrot

Yeah the -Dkotest.filter.specs and -Dkotest.filter.tests are 5.x only.

sksamuel avatar Jan 29 '22 03:01 sksamuel

Yes it's available in 5. So we can update this now.

On Fri, 4 Feb 2022 at 15:15, Reza Malik @.***> wrote:

@sksamuel https://github.com/sksamuel Did this already make it into 5.x?

— Reply to this email directly, view it on GitHub https://github.com/kotest/kotest-gradle-plugin/issues/3#issuecomment-1030354528, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGUL2WUADTHDUJPDJFTUZQ6VHANCNFSM4R3DNLXQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

sksamuel avatar Feb 04 '22 21:02 sksamuel

Thanks for working on getting this in

rezammalik avatar Feb 04 '22 21:02 rezammalik