-
Hello folks. I have the following simple test class: package com.cisco.iot.test.sample
import org.junit.jupiter.api.*
import org.junit.jupiter.api.extension.*
import java.util.stream.Stream
import kotlin.test.assertTrue
class CtInvocationContextProvider : ClassTemplateInvocationContextProvider {
override fun supportsClassTemplate(context: ExtensionContext): Boolean = true
override fun provideClassTemplateInvocationContexts(context: ExtensionContext): Stream<ClassTemplateInvocationContext> {
return Stream.of(
object : ClassTemplateInvocationContext {
override fun prepareInvocation(context: ExtensionContext) {
context.getStore(ExtensionContext.Namespace.GLOBAL).put("hostPlatform", "HOST_PLATFORM_1")
}
},
object : ClassTemplateInvocationContext {
override fun prepareInvocation(context: ExtensionContext) {
context.getStore(ExtensionContext.Namespace.GLOBAL).put("hostPlatform", "HOST_PLATFORM_2")
}
},
)
}
}
class CtParameterResolver : ParameterResolver {
override fun supportsParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Boolean = true
override fun resolveParameter(parameterContext: ParameterContext, extensionContext: ExtensionContext): Any =
extensionContext.getStore(ExtensionContext.Namespace.GLOBAL).get("hostPlatform")
}
@ClassTemplate
@ExtendWith(
CtInvocationContextProvider::class,
CtParameterResolver::class,
)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SampleTest {
@BeforeAll
fun setup(hostPlatform: String) {
println("Setting up test for hostPlatform: $hostPlatform")
}
@Test
fun foo(hostPlatform: String) {
println("Running foo test for hostPlatform: $hostPlatform")
assertTrue(true)
}
}
My purpose is to have two instances of SampleTest, each with its own Essentially, only one instance of Is this the expected behaviour here or am I missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
If I remove the parameter from |
Beta Was this translation helpful? Give feedback.
Have you taken a look at
@BeforeParameterizedClassInvocation
?