With this release, we are pleased to also announce the first RC of Micronaut Test: a simple collection of extensions for JUnit 5 and Spock that adds a few niceties that make it simpler to test Micronaut applications.

Micronaut Test adds the following testing-specific features to Micronaut:

Automatically start and stop the server for the scope of a test suite

Use mocks to replace existing beans for the scope of a test suite

Allow dependency injection into a test instance

The following is an example test written in Spock:

packageio.micronaut.test.spock

importio.micronaut.test.annotation.MicronautTest

importspock.lang.*

importjavax.inject.Inject

@MicronautTest

class MathServiceSpec extends Specification {

@Inject

MathService mathService

@Unroll

void"should compute #num times 4"(){

when:

def result = mathService.compute(num)

then:

result == expected

where:

num | expected

2|8

3|12

}

}

As you can see from the example above, simply by adding the @MicronautTest annotation to any Spock or JUnit 5 test, the test automatically becomes a candidate for dependency injection.

Micronaut Test includes many more features, including integration with Spock's mocking framework and Mockito for JUnit 5.

Thanks to all those who provided feedback during the RC process and to those who plan to attend Oracle Code One 2018 next week in San Francisco - see you there!