Spring profiles and testing

前端 未结 5 1882
耶瑟儿~
耶瑟儿~ 2020-12-24 10:36

I\'ve got a web application where I have the typical problem that it requires different configuration files for different environments. Some configuration is placed in the a

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 10:58

    Looking at Biju's answer I found a working solution.

    I created an extra context-file test-context.xml:

    
    

    Containing the profile:

    spring.profiles.active=localtest
    

    And loading the test with:

    @RunWith(SpringJUnit4ClassRunner.class)
    @TestExecutionListeners({
        TestPreperationExecutionListener.class
        })
    @Transactional
    @ActiveProfiles(profiles = "localtest")
    @ContextConfiguration(locations = {
        "classpath:config/test-context.xml" })
    public class TestContext {
    
      @Test
      public void testContext(){
    
      }
    }
    

    This saves some work when creating multiple test-cases.

提交回复
热议问题