1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【spock】application.propertiesの外部設定値を取得する(ダミーのproperty設定)

Posted at

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:
        //省略
    }

おわり

上記のように記載してあげればよしなにしてくれる

1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?