문제

We have a set of integration tests that we use to verify various things, including that our database is in a sane state per environment (Dev,Test,Qa,etc) in correlation to our JPA mappings and other data dependent items.

We configure which database, and other environment specific things we are connecting to via a Spring Profile. This works great on our automated build, where we set the environment variable "spring.profiles.active" to whatever environment we are in, run the integration tests, and easily locate configuration errors, and other things that can sometimes be overlooked.

However, what I would like, is the ability to set the spring.profiles.default attribute to "dev" in the integration test suite so that when a developer runs them from the IDE, they don't get errors complaining about the lack of a profile being set. We do this in the web.xml for a real deployment, but what I want to know is how can I hook into the AbstractTransactionalJUnit4SpringContextTests (or elsewhere) to accomplish this?

도움이 되었습니까?

해결책 2

does not seem to be a way of doing this, so resorted to setting the environment variable spring.profiles.active to "dev" in the default run config for junit in Intellij.

다른 팁

Out of top of my head, you're using AbstractTransactionalJUnit4SpringContextTests which means that you can have access to an instance of ConfigurableApplicationContext. I believe you can say:

class BaseTest extends ATJ4SCT {

  @Autowired
  ConfigurableApplicationContext context;

  @Before
  public void setUp() {
    ConfigurableEnvironment env = context.getEnvironment();
    env.setDefaultProfiles("dev");
    // not sure but if necessary
    context.refresh();

  }

}

Reference: ConfigurableEnvironment#setDefaultProfiles(String...).

Although different topic but may be also worth it to take a look at this question.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top