Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

In a previous blog entry, I wrote about hot to Get the active Springframework profiles. In this one, I had the need to set the profile for a test. Keep in mind, I am not setting which profile the test should be included in, but which profile should be activated when the test runs.

We had the dataSources defined in a local profile and a default profile. In this case, I needed the test to use the local profile. It turned out to be pretty easy. All I had to do was annotate the test class with @ActiveProfiles. The value inside the annotation can contain multiple profiles, separated by commas.

@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("local")
public class EventServiceTest {
   //...
}

August 23rd, 2017

Posted In: Spring

Leave a Reply

Your email address will not be published. Required fields are marked *

LinkedIn Auto Publish Powered By : XYZScripts.com