https://kotlinlang.org logo
#minutest
Title
# minutest
d

dave08

03/24/2020, 8:55 AM
Good morning @dmcg! I'm trying to get minutest up in a microservice, but I'm getting no tests found...
Copy code
Testing started at 10:53 AM ...
> Task :cleanTest
> Task :kaptGenerateStubsKotlin UP-TO-DATE
> Task :kaptKotlin UP-TO-DATE
> Task :compileKotlin UP-TO-DATE
> Task :compileJava NO-SOURCE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :kaptGenerateStubsTestKotlin
> Task :kaptTestKotlin
w: [kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: com.squareup.moshi.kotlin.codegen.JsonClassCodegenProcessor (NON_INCREMENTAL), javaslang.match.PatternsProcessor (NON_INCREMENTAL).
> Task :compileTestKotlin
> Task :compileTestJava NO-SOURCE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test FAILED
~~~ Project Configuration ~~~
-> Parallelism: 1 thread
-> Test order: LexicographicSpecExecutionOrder
-> Soft assertations: False
-> Write spec failure file: False
-> Fail on ignored tests: False
-> Extensions
  - io.kotlintest.extensions.SystemPropertyTagExtension
  - io.kotlintest.extensions.RuntimeTagExtension
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [controller.SomeManagerControllerTest](filter.includeTestsMatching)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at <https://help.gradle.org>
BUILD FAILED in 4s
9 actionable tasks: 5 executed, 4 up-to-date
With JUnit5
d

dmcg

03/24/2020, 9:01 AM
You’re extending JUnit5Minutests? Try putting a plain old @Test fun in the same class and see if that is run
d

dave08

03/24/2020, 9:02 AM
Yes, I extended that. and even old
@Test
doesn'
doesn't work
I had kotlintest there too, so maybe it's causing problems?
d

dmcg

03/24/2020, 9:03 AM
Then I’d say you have a bigger problem than minutest! Is all the junit engine stuff in place in your Gradle build?
d

dave08

03/24/2020, 9:03 AM
Copy code
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.4.1")

    testImplementation("io.kotlintest:kotlintest-runner-junit5:3.4.1")

    testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.2")
    testImplementation("dev.minutest:minutest:1.11.0")
    testImplementation("io.strikt:strikt-core:0.24.0")
    testImplementation("io.mockk:mockk:1.9.3")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.3.2")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.3.2")
Copy code
val test by tasks.getting(Test::class) {
    useJUnitPlatform { }
}
In kotlin dsl
d

dmcg

03/24/2020, 9:04 AM
I know that Kotlintest has some issue - can you try without it
d

dave08

03/24/2020, 9:08 AM
still not working 😧
I don't really know what this means:
No tests found for given includes: [controller.SomeManagerControllerTest](filter.includeTestsMatching)
Do I need some extra configs?
It seems like Intellij has junit jupiter (api/engine) 5.6.0, platform (commons/engine/launcher) 1.6.0 in its dependency list (newer than what you have on the site), could that be the problem?
oops wrong import for
@Test
...
Looks like kotlintest was the problem... but it's still funny that intellij shows
minutests()[1][1]
as the
test
name...
Is there a bug in gradle 6.2.2 for getting test names @dmcg?
d

dmcg

03/24/2020, 10:04 AM
Between JUnit and Gradle yes. If you run tests in IntelliJ with the IntelliJ runner not the Gradle runner they show up ok
for me!
d

dave08

03/24/2020, 10:12 AM
Ok thanks, I'll give it a try!
It works nicely 😃 ! But is there any way to get rid of the extra minutests() nesting?
d

dmcg

03/24/2020, 3:52 PM
There is the Minutest engine!
d

dave08

03/24/2020, 3:53 PM
?
d

dmcg

03/25/2020, 9:02 AM
@natpryce wrote an engine that uses the JUnit 5 test discovery but not runner. Maybe he can explain how to use it?
n

natpryce

03/25/2020, 9:20 AM
The MinutestEngine plugs into the JUnit runner, giving you nested tests and suites
The TestEngine API is the “official” way to extend JUnit 5 for different test frameworks
d

dave08

03/25/2020, 9:23 AM
So how is it used with Minutest?
n

natpryce

03/25/2020, 9:25 AM
You need to tell one of the layers of JUnit 5 to use the Minutest engine. You can configure it in Gradle. Also in the IntelliJ test runner config dialog.
In gradle you add the config :
Copy code
useJunitPlatform {
   includeEngines("junit-jupiter", "junit-vintage", "minutest")
}
to your junit config block
However, it’s experimental so be warned it may not do everything you need. It could do with someone to look after it hint hint :-D
d

dave08

03/25/2020, 9:34 AM
Right now, I have that config without includeEngines inside, it still runs the tests but includes:
Copy code
TestClass
|_ minutest()
   |_Context
     |_Test
minutest() looks a bit funny there and wastes one indenting.
n

natpryce

03/25/2020, 9:35 AM
That looks like the JUnit5 support. The minutest engine expects tests to be written as top-level functions.
d

dave08

03/25/2020, 9:45 AM
You mean just
Copy code
fun someClassTest() = rootContext {
...
}
at the top level?
with no class around it
n

natpryce

03/25/2020, 9:57 AM
Yes
It had to be annotated I recall
Let me take a look on GitHub to remind myself
No, no annotations needed.
The test engine picks up top-level function that return a root context
d

dave08

03/25/2020, 10:02 AM
Nice 😃! So what kind of quirks could there be here?
n

natpryce

03/25/2020, 10:03 AM
Not sure. I’ve not worked on Minutest for quite a long time, and Duncan has focused on the JUnit5 Jupiter integration rather than the test engine.
It might be that you need to annotate functions to get IntelliJ to recognise them as tests in the code editor
d

dave08

03/25/2020, 10:04 AM
Ok, thanks!
d

dmcg

03/25/2020, 12:05 PM
Yes, getting IntelliJ to recognise them as runnable was the block I stumbled over last night
n

natpryce

03/26/2020, 4:23 PM
If you run all the tests, then you can run individual tests from the tree of tests in the IntelliJ test runner (which is an improvement on when running Minutest from JUnit 5 or JUnit 4).
d

dmcg

03/26/2020, 4:23 PM
I think that I did get that working for JUnit5
Sorry 😉
n

natpryce

03/26/2020, 4:24 PM
Even for tests within subcontexts?
d

dmcg

03/26/2020, 4:25 PM
I think so, away from non-bank computer ATM
n

natpryce

03/26/2020, 4:28 PM
I recall that annotating top-level functions with
@Testable
made IntelliJ treat them as runnable test methods
(And I assume any annotation that is itself meta-annotated with
@Testable
would work)
d

dmcg

03/30/2020, 8:43 AM
Oooh - let me have a look at that (in my copious free time)
9 Views