I upgraded the Kotest version from <kotest.vers...
# kotest
r
I upgraded the Kotest version from <kotest.version>4.6.4</kotest.version> to <kotest.version>5.1.0</kotest.version> in my maven pom. and now I'm getting the following error. this is a spring boot project with 100% Kotlin.
I also have following plugin in my pom
<plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <executions> <execution> <id>compile</id> <configuration> <sourceDirs> <sourceDir>${project.basedir}/src/main/kotlin</sourceDir> </sourceDirs> </configuration> </execution> <execution> <id>test-compile</id> <configuration> <sourceDirs> <sourceDir>${project.basedir}/src/test/kotlin</sourceDir> </sourceDirs> </configuration> </execution> </executions> <configuration> <compilerPlugins> <plugin>all-open</plugin> <plugin>spring</plugin> </compilerPlugins> <args> <arg>-Xjsr305=strict</arg> </args> </configuration> <dependencies> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-noarg</artifactId> <version>${kotlin.version}</version> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-allopen</artifactId> <version>${kotlin.version}</version> </dependency> </dependencies> </plugin>
getting following error
[INFO] Running ComponentTestBadFlightReturned io.kotest.engine.spec.SpecInstantiationException: Could not create instance of class ComponentTestBadFlightReturned. Specs must have a public zero-arg constructor. at io.kotest.engine.spec.InstantiateSpecKt.javaReflectNewInstance(instantiateSpec.kt:46) at io.kotest.engine.spec.InstantiateSpecKt.createAndInitializeSpec(instantiateSpec.kt:30) at io.kotest.engine.spec.InstantiateSpecKt.instantiate(instantiateSpec.kt:11) at io.kotest.engine.spec.SpecRefKt.instance(SpecRef.kt:14) <<intermediate calls ommitted>> at io.kotest.common.RunBlockingKt.runBlocking(runBlocking.kt:3) at io.kotest.engine.TestEngineLauncher.launch(TestEngineLauncher.kt:194) at io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine.execute(KotestJunitPlatformTestEngine.kt:80) at io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine.execute(KotestJunitPlatformTestEngine.kt:44) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67) at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86) at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86) at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53) at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150) at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124) at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345) at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418) [ERROR] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.019 s <<< FAILURE! - in ComponentTestBadFlightReturned [ERROR] SpecInstantiationException Time elapsed: 0 s <<< ERROR! io.kotest.engine.spec.SpecInstantiationException: Could not create instance of class ComponentTestBadFlightReturned. Specs must have a public zero-arg constructor. [ERROR] ComponentTestBadFlightReturned Time elapsed: 0 s <<< ERROR! io.kotest.engine.spec.SpecInstantiationException: Could not create instance of class ComponentTestBadFlightReturned Caused by: io.kotest.engine.spec.SpecInstantiationException: Could not create instance of ComponentTestBadFlightReturned. Specs must have a public zero-arg constructor. [INFO] [INFO] Results: [INFO] [ERROR] Errors: [ERROR] ComponentTestBadFlightReturned » SpecInstantiation Could not create instance o... [ERROR] ComponentTestBadFlightReturned » SpecInstantiation Could not create instance o...
and following is the test code snippet:
@TestConfiguration class TestConfig { @MockBean private lateinit var confidentialClientApplication: ConfidentialClientApplication @MockBean private lateinit var authenticationResult: IAuthenticationResult } @RestClientTest(SomeService::class) @ContextConfiguration(classes = [TestConfig::class, Configuration::class]) class ComponentTestBadFlightReturned @Autowired constructor( private val consumer: Consumer, restTemplate: RestTemplate, confidentialClientApplication: ConfidentialClientApplication, authenticationResult: IAuthenticationResult ) : BehaviorSpec() { override fun listeners() = listOf(SpringListener) @Value("\${service.agt.ssms.accessScope}") private lateinit var accessScope: String private var mockRestServer = MockRestServiceServer.createServer(restTemplate) init { Mockito.`when`(confidentialClientApplication.acquireToken(any(ClientCredentialParameters::class.java))) .thenReturn(CompletableFuture.completedFuture(authenticationResult)) Given("somethig is given") { <!- code stmts here -> mockRestServer.expectInitializationCommands() When("when is here") { mockRestServer.setUpMocked404NoneListedException(".*", GET) } Then("something happened") { mockRestServer.expectSSMSConnectionToBeClosed() consumer.consume(SimpleMessage("${UUID.randomUUID()}", getId(), false).toJsonString(jsonDateFormat)) mockRestServer.verify() } } mockRestServer.reset() } }
spring boot version used:
Copy code
<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>2.6.2</version>
</parent>
Kotlin version used
Copy code
<kotest.version>5.1.0</kotest.version>
<kotlin-coroutines.version>1.6.0</kotlin-coroutines.version>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<kotlin.version>1.6.10</kotlin.version>
other Kotest related dependencies
Copy code
<dependency>
   <groupId>io.kotest</groupId>
   <artifactId>kotest-runner-junit5-jvm</artifactId>
   <version>${kotest.version}</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>io.kotest</groupId>
   <artifactId>kotest-assertions-core-jvm</artifactId>
   <version>${kotest.version}</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>io.kotest</groupId>
   <artifactId>kotest-assertions-json-jvm</artifactId>
   <version>${kotest.version}</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>io.kotest</groupId>
   <artifactId>kotest-property-jvm</artifactId>
   <version>${kotest.version}</version>
   <scope>test</scope>
</dependency>
<dependency>
   <groupId>io.kotest</groupId>
   <artifactId>kotest-extensions-spring-jvm</artifactId>
   <version>4.4.3</version>
   <scope>test</scope>
</dependency>
t
extensions moved, I think you should use
Copy code
<dependency>
   <groupId>io.kotest.extensions</groupId>
   <artifactId>kotest-extensions-spring/artifactId>
   <version>1.1.0</version>
   <scope>test</scope>
</dependency>
instead of
kotest-extensions-spring-jvm
👍 1
r
yes, this one worked. thanks @thanksforallthefish
1034 Views