LoginSignup
7
6

More than 5 years have passed since last update.

SpringBootテスト時に一部のプロパティだけを上書きする

Posted at

SpringBootのアプリケーションをテストする際には以下のように書きますが、

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SpringBootConfig.class)
public class HogeServiceTest {
}

特定のテストの時だけ、一部プロパティを上書きしたいような場合は次のように書くと便利かもしれません。

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { SpringBootConfig.class, HogeServiceTest.class })
@Configuration
@PropertySource(value = "classpath:/override.properties")
public class HogeServiceTest {
}

override.propertiesには、変更したいプロパティだけを書いておきます。

7
6
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
7
6