how to run/turn off selective tests based on profiles in spring boot

前端 未结 5 952
梦谈多话
梦谈多话 2020-12-10 13:47

I have a spring-boot application for which I am writing IT tests.

The data for the tests comes from application-dev.properties when I activ

5条回答
  •  感情败类
    2020-12-10 14:30

    I wanted to exclude tests that required an external service but I couldn't get that to work the way I wanted (more or less a non-existent @IfNotProfileValue).

    As an alternative, I used the JUnit Assume.assumeThat which provided the behavior I wanted. e.g.,

    Assume.assumeThat("Skipping Test: No username property", this.username, not(isEmptyString()));
    

    I ended up not using a profile to drive it but you should be able to define a property or use the Environment to determine if a profile is active.

    The assumeThat can be used in @Test and @Before methods but be aware that the @After methods will still run so cleanup might need a code guard.

提交回复
热议问题