Skip to content

sherviiin/quarkus-mockk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quarkus JUnit5 MockK Extension

GitHub Actions Status Version License

Description

This Quarkus JUnit5 MockK extension allows you to easily inject MockK mocks.

The full documentation be found here.

Importing the dependency

First of all, you need to add the following dependency:

<dependency>
    <groupId>io.quarkiverse.mockk</groupId>
    <artifactId>quarkus-junit5-mockk</artifactId>
    <version>LATEST</version>
    <scope>test</scope>
</dependency>

If you are using gradle:

dependencies {
    testImplementation 'io.quarkiverse.mockk:quarkus-junit5-mockk:LATEST'
}

Compatibility with Quarkus

Starting with Quarkus 2.8 and above, version 1.1.0 of quarkus-junit5-mockk should be used. If you use a version before 2.7, version 1.0.1 of quarkus-junit5-mockk should be used.

Example

Now, you can use @InjectMock and @InjectSpy in your test such as:

@QuarkusTest
class InjectionMockTest {

    @Inject
    private lateinit var firstService: FirstService

    @InjectMock
    private lateinit var secondService: SecondService

    @Test
    fun `should respond test`() {
        every { secondService.greet() } returns "test"
        assertThat(firstService.greet()).isEqualTo("test")
    }

    @Test
    fun `should respond second`() {
        every { secondService.greet() } returns "second"
        assertThat(firstService.greet()).isEqualTo("second")
        verify { secondService.greet() }
    }
}

About

Mockk Quarkus Extension

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%