Skip to content

micronaut-projects/micronaut-test

Folders and files

NameName
Last commit message
Last commit date
Feb 7, 2025
Nov 6, 2024
Feb 7, 2023
Mar 26, 2025
Feb 7, 2025
Sep 11, 2023
Nov 6, 2024
Nov 6, 2024
Nov 6, 2024
Nov 6, 2024
Nov 6, 2024
Nov 6, 2024
Nov 6, 2024
Dec 9, 2024
Oct 17, 2023
Mar 29, 2023
Dec 1, 2023
Jun 3, 2020
Jun 3, 2020
Dec 1, 2023
Feb 5, 2024
Dec 1, 2023
May 19, 2023
Feb 7, 2025
Feb 7, 2025
Jul 15, 2024
Jan 10, 2025

Repository files navigation

Spock: Maven Central JUnit 5: Maven Central Kotest: Maven Central Kotest 5: Maven Central Quality Gate Status

Micronaut Test

This project provides testing extension for JUnit 5, Spock and Kotest to make it easier to test Micronaut applications.

For more information see the Latest or Snapshot Documentation.

Example Spock Test:

import io.micronaut.test.annotation.MicronautTest
import spock.lang.*
import jakarta.inject.Inject

@MicronautTest // Declares the test as a micronaut test
class MathServiceSpec extends Specification {

    @Inject
    MathService mathService // Dependency injection is used to supply the system under test

    @Unroll
    void "should compute #num times 4"() { // This is the test case. #num will be replaced by the values defined in the where: block
        when:
        def result = mathService.compute(num)

        then:
        result == expected

        where:
        num | expected
        2   | 8
        3   | 12
    }
}

Example JUnit 5 Test:

import io.micronaut.test.annotation.MicronautTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import jakarta.inject.Inject;


@MicronautTest // Declares the test as a micronaut test
class MathServiceTest {

    @Inject
    MathService mathService; // Dependency injection is used to supply the system under test


    @ParameterizedTest
    @CsvSource({"2,8", "3,12"})
    void testComputeNumToSquare(Integer num, Integer square) {
        final Integer result = mathService.compute(num); // Injected bean can be used in test case

        Assertions.assertEquals(
                square,
                result
        );
    }
}

Snapshots and Releases

Snaphots are automatically published to JFrog OSS using Github Actions.

See the documentation in the Micronaut Docs for how to configure your build to use snapshots.

Releases are published to JCenter and Maven Central via Github Actions.

A release is performed with the following steps: