<@UFGCACPE0> Is there a way to use Prepared with J...
# opensavvy
d
@CLOVIS Is there a way to use Prepared with Junit5? I want to run ApprovalTests on it but it doesn't support Kotest...
c
Do you mean kotlin-test, or JUnit5 directly?
d
I get this error: Could not find Junit/TestNg TestCase you are running, supported frameworks: Junit3, Junit4, Junit5, TestNg
If kotlin-test would help solve that, then great!
c
There's a stale PR here with direct JUnit5 support: https://gitlab.com/opensavvy/groundwork/prepared/-/merge_requests/7
You can also use the kotlin-test runner, which supports JUnit5 (but NOT junit4): https://opensavvy.gitlab.io/groundwork/prepared/api-docs/runners/runner-kotlin-test/index.html
The declaration syntax is slightly different
(and it doesn't support the same platforms)
d
I guess I'll try with kotlin-test and see if it works first, thanks!
c
Do notice the platform-specific setup instructions
d
Can I have both the kotest and kotlin-test deps in the same project?
Oh, I don't get the run arrow in the ide... 🤒, and it still gives me the same error:
Copy code
Could not find Junit/TestNg TestCase you are running, supported frameworks: Junit3, Junit4, Junit5, TestNg
java.lang.RuntimeException: Could not find Junit/TestNg TestCase you are running, supported frameworks: Junit3, Junit4, Junit5, TestNg
	at org.approvaltests.namer.AttributeStackSelector.selectElement(AttributeStackSelector.java:69)
	at com.spun.util.tests.TestUtils.getCurrentFileForMethod(TestUtils.java:181)
	at com.spun.util.tests.TestUtils.getCurrentFileForMethod(TestUtils.java:174)
	at org.approvaltests.namer.StackTraceNamer.<init>(StackTraceNamer.java:17)
	at org.approvaltests.Approvals$1.load(Approvals.java:41)
	at org.approvaltests.Approvals$1.load(Approvals.java:38)
	at org.approvaltests.Approvals.createApprovalNamer(Approvals.java:265)
I think they use the junit5 api to get the test name...
Maybe I can use
by prepared { }
w/o the suite/test structure in regular junit5 @CLOVIS?
Or maybe this library would work: https://github.com/dmcg/okey-doke#junit-5? with that register extension?
c
You can use these functions to instantiate a TestDsl anywhere: https://gitlab.com/opensavvy/groundwork/prepared/-/blob/main/suite/src/commonMain/kotlin/RunTest.kt?ref_type=heads but if you do that, you won't have suites/nested tests
That stacktrace you showed does not come from my code, I don't think Prepared can do anything about it
if you're using the
kotlin-test
runner on the JVM, it does use JUnit5
This seems to be the check for junit5:
Copy code
try
      {
        Class.forName("org.junit.platform.commons.annotation.Testable");
        isJunit5Present = true;
      }
      catch (ClassNotFoundException e)
      {
        isJunit5Present = false;
      }
I tried runTestDsl with junit5, but I got:
Copy code
After waiting for 10s, the test coroutine is not completing, there were active child jobs: [UndispatchedCoroutine{Active}@6d7c9508]
kotlinx.coroutines.test.UncompletedCoroutinesError: After waiting for 10s, the test coroutine is not completing, there were active child jobs: [UndispatchedCoroutine{Active}@6d7c9508]
	at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1$2$1.invoke(TestBuilders.kt:351)
	at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1$2$1.invoke(TestBuilders.kt:335)
	at kotlinx.coroutines.InternalCompletionHandler$UserSupplied.invoke(CompletionHandler.common.kt:67)
	at kotlinx.coroutines.InvokeOnCancelling.invoke(JobSupport.kt:1438)
	at kotlinx.coroutines.JobSupport.notifyCancelling(JobSupport.kt:1483)
	at kotlinx.coroutines.JobSupport.tryMakeCancelling(JobSupport.kt:806)
	at kotlinx.coroutines.JobSupport.makeCancelling(JobSupport.kt:766)
	at kotlinx.coroutines.JobSupport.cancelImpl$kotlinx_coroutines_core(JobSupport.kt:682)
	at kotlinx.coroutines.JobSupport.cancelCoroutine(JobSupport.kt:669)
	at kotlinx.coroutines.TimeoutCoroutine.run(Timeout.kt:156)
	at kotlinx.coroutines.EventLoopImplBase$DelayedRunnableTask.run(EventLoop.common.kt:498)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:277)
	at kotlinx.coroutines.DefaultExecutor.run(DefaultExecutor.kt:105)
	at java.base/java.lang.Thread.run(Thread.java:840)
Copy code
@Test
    fun test1() = runTestDsl("test", EmptyCoroutineContext, TestConfig.Empty) {
...
c
This seems to be the check for junit5:
``` try
{
Class.forName("org.junit.platform.commons.annotation.Testable");
isJunit5Present = true;
}
catch (ClassNotFoundException e)
{
isJunit5Present = false;
}```
I mean… I guess you could create that annotation yourself.
What is it trying to even do here? that's so weird 😕
d
It seems to be trying to find out how to resolve the test name, so first it needs to find out if I'm using junit 3/4/5...
c
But that's never going to work with Prepared or Kotest, the test name isn't written in the source code.
Why does a library even want to know the test name 😕 is there no way you can give it to it?
d
Yeah, it seems like currently the two only libraries that do approval testing do that... I thought the same thing as you 😞.