Spring-boot default profile for integration tests

后端 未结 11 1073
说谎
说谎 2020-12-07 14:49

Spring-boot utilizes Spring profiles (http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html) which allow for instance to have separate co

11条回答
  •  我在风中等你
    2020-12-07 14:53

    Another way to do this is to define a base (abstract) test class that your actual test classes will extend :

    @RunWith(SpringRunner.class)
    @SpringBootTest()
    @ActiveProfiles("staging")
    public abstract class BaseIntegrationTest {
    }
    

    Concrete test :

    public class SampleSearchServiceTest extends BaseIntegrationTest{
    
        @Inject
        private SampleSearchService service;
    
        @Test
        public void shouldInjectService(){
            assertThat(this.service).isNotNull();
        }
    } 
    

    This allows you to extract more than just the @ActiveProfiles annotation. You could also imagine more specialised base classes for different kinds of integration tests, e.g. data access layer vs service layer, or for functional specialties (common @Before or @After methods etc).

提交回复
热议问题