LoginSignup
1
0

More than 1 year has passed since last update.

【SpringBoot】SpringBootTest実行時にapplication.properties/yaml/ymlの設定を上書きする

Posted at

やり方

SpringBootTestアノテーションのpropertiesに値を設定することでapplication.propertiesに設定された値を上書きすることができます。

サンプルコード

以下のコードでは、ApplicationTestsの実行時のみlazy-initializationを無効にしています。

import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest

// lazy-initializationを切ることで全Beanが正常に初期化されることをテストしている
@SpringBootTest(properties = ["spring.main.lazy-initialization=false"])
class ApplicationTests {

    @Test
    fun contextLoads() {
    }
}

補足

この他にも特定のテストで設定を上書きする方法は幾つかあります。
下記のページなどが参考になると思います。

1
0
0

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