application.propertiesに設定している値を
コントローラやサービスで取得することがあると思います。
今回はそれのspockの書き方メモ
application.properties
test.param=test_aaaaaaaa
Controller
//省略
@Value("test.param")
private String param;
//省略
spock側ではこう書く
ServiceImplTest
@RunWith(Sputnik.class)
class ServiceImplTest extends Specification {
SampleController target
def setup() {
target = new SampleController()
}
@Unroll
def "application.propertiesの外部設定値を取得する"() {
setup:
ReflectionTestUtils.setField(target, "param", "test_aaaaaaaa")
when:
//省略
then:
//省略
where:
//省略
}
おわり
上記のように記載してあげればよしなにしてくれる