Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure integration tests in Spring Boot

I'm using Spring Boot (packed to classic WAR without SpringBoot runner) and I'd like to implement integration tests in Spock. When I use @ContextConfiguration(classes = MySpringConfiguration.class) then only "standard" Spring context is used (without any benefits from Boot, like for example @EnableConfigurationProperties.

like image 921
Jakub Kubrynski Avatar asked Nov 29 '25 10:11

Jakub Kubrynski


1 Answers

@ContextConfiguration(classes = Application, loader = SpringApplicationContextLoader)
class FooSpec extends Specification {

    @Autowired
    private CustomProperties customProperties;

    def "should read spring boot properties"() {

        when:
            def foo = customProperties.foo;
        then:
            foo
    }

}

I love Spock!

Update

As @gilad said, this is not needed in Spring Boot 1.3+

like image 155
MariuszS Avatar answered Dec 01 '25 13:12

MariuszS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!