<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Spring-boot default profile for integration tests in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Spring-boot-default-profile-for-integration-tests/m-p/83655#M52763</link>
    <description>&lt;P&gt;As far as I know there is nothing directly addressing your request - but I can suggest a proposal that could help:&lt;/P&gt;&lt;P&gt;You could use your own test annotation that is a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-meta-annotations" target="_blank" rel="noopener noreferrer"&gt;meta annotation&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;comprising&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;@SpringBootTest&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;@ActiveProfiles("test"). So you still need the dedicated profile but avoid scattering the profile definition across all your test.&lt;/P&gt;&lt;P&gt;This annotation will default to the profile&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;test&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and you can override the profile using the meta annotation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;@Retention(RetentionPolicy.RUNTIME)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@Target(ElementType.TYPE)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@SpringBootTest&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@ActiveProfiles&lt;/SPAN&gt;
&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;@interface&lt;/SPAN&gt; MyApplicationTest {
  &lt;SPAN class=""&gt;@AliasFor(annotation = ActiveProfiles.class, attribute = "profiles")&lt;/SPAN&gt; String[] activeProfiles() &lt;SPAN class=""&gt;default&lt;/SPAN&gt; {&lt;SPAN class=""&gt;"test"&lt;/SPAN&gt;};
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Aug 2022 07:11:24 GMT</pubDate>
    <dc:creator>KamaalJema</dc:creator>
    <dc:date>2022-08-05T07:11:24Z</dc:date>
    <item>
      <title>Spring-boot default profile for integration tests</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Spring-boot-default-profile-for-integration-tests/m-p/83588#M52722</link>
      <description>&lt;P&gt;Spring-boot utilizes&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html" target="_blank" rel="noopener noreferrer"&gt;Spring profiles&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;which allow for instance to have separate config for different environments. One way I use this feature is to configure test database to be used by integration tests. I wonder however is it necessary to create my own profile 'test' and explicitly activate this profile in each test file? Right now I do it in the following way:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;Create application-test.properties inside src/main/resources&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Write test specific config there (just the database name for now)&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;In every test file include:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;@ActiveProfiles("test")&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Is there a smarter / more concise way? For instance a default test profile?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 05:40:34 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Spring-boot-default-profile-for-integration-tests/m-p/83588#M52722</guid>
      <dc:creator>JernalinSadhoo</dc:creator>
      <dc:date>2022-08-01T05:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Spring-boot default profile for integration tests</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Spring-boot-default-profile-for-integration-tests/m-p/83655#M52763</link>
      <description>&lt;P&gt;As far as I know there is nothing directly addressing your request - but I can suggest a proposal that could help:&lt;/P&gt;&lt;P&gt;You could use your own test annotation that is a&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#beans-meta-annotations" target="_blank" rel="noopener noreferrer"&gt;meta annotation&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;comprising&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;@SpringBootTest&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;@ActiveProfiles("test"). So you still need the dedicated profile but avoid scattering the profile definition across all your test.&lt;/P&gt;&lt;P&gt;This annotation will default to the profile&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;test&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;and you can override the profile using the meta annotation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;@Retention(RetentionPolicy.RUNTIME)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@Target(ElementType.TYPE)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@SpringBootTest&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@ActiveProfiles&lt;/SPAN&gt;
&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;@interface&lt;/SPAN&gt; MyApplicationTest {
  &lt;SPAN class=""&gt;@AliasFor(annotation = ActiveProfiles.class, attribute = "profiles")&lt;/SPAN&gt; String[] activeProfiles() &lt;SPAN class=""&gt;default&lt;/SPAN&gt; {&lt;SPAN class=""&gt;"test"&lt;/SPAN&gt;};
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2022 07:11:24 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Spring-boot-default-profile-for-integration-tests/m-p/83655#M52763</guid>
      <dc:creator>KamaalJema</dc:creator>
      <dc:date>2022-08-05T07:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Spring-boot default profile for integration tests</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Spring-boot-default-profile-for-integration-tests/m-p/83911#M52905</link>
      <description>&lt;P&gt;Another way to do this is to define a base (abstract) test class that your actual test classes will extend :&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;@RunWith(SpringRunner.class)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@SpringBootTest()&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@ActiveProfiles("staging")&lt;/SPAN&gt;
&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;abstract&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;BaseIntegrationTest&lt;/SPAN&gt; {
}&lt;/PRE&gt;&lt;P&gt;Concrete test :&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;SampleSearchServiceTest&lt;/SPAN&gt; &lt;SPAN class=""&gt;extends&lt;/SPAN&gt; &lt;SPAN class=""&gt;BaseIntegrationTest&lt;/SPAN&gt;{

    &lt;SPAN class=""&gt;@Inject&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;private&lt;/SPAN&gt; SampleSearchService service;

    &lt;SPAN class=""&gt;@Test&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;void&lt;/SPAN&gt; &lt;SPAN class=""&gt;shouldInjectService&lt;/SPAN&gt;&lt;SPAN class=""&gt;()&lt;/SPAN&gt;{
        assertThat(&lt;SPAN class=""&gt;this&lt;/SPAN&gt;.service).isNotNull();
    }
} &lt;/PRE&gt;&lt;P&gt;This allows you to extract more than just the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;@ActiveProfiles&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;annotation. You could also imagine more specialized base classes for different kinds of integration tests, e.g. data access layer vs service layer, or for functional specialties (common&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;@Before&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;or&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;@After&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;methods etc).&lt;/P&gt;&lt;P&gt;Along with the approach below, you can also add config to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;src/test/resources/config/application.yml&lt;/P&gt;&lt;PRE&gt;src/
├── main/
│   ├── java/
│   │   └── ...
│   └── resources/
│       └── application.yml &amp;lt;- default properties, always loaded
└── test/
    ├── java/
    │   └── ...
    └── resources/
        └── config/
            └── application.yml &amp;lt;- test properties, will override the defaults&lt;/PRE&gt;&lt;P&gt;&lt;A href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files" target="_blank" rel="nofollow noopener noreferrer"&gt;https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.files&amp;nbsp;&lt;/A&gt;&lt;A href="https://omegle.ws" target="_blank" rel="noopener"&gt;/ome&lt;/A&gt;&lt;A href="https://omegle.club" target="_blank" rel="noopener"&gt;gle&lt;/A&gt;&lt;A href="https://shagle.download" target="_blank" rel="noopener"&gt;shagle&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Aug 2022 11:34:29 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Spring-boot-default-profile-for-integration-tests/m-p/83911#M52905</guid>
      <dc:creator>KamaalJema</dc:creator>
      <dc:date>2022-08-25T11:34:29Z</dc:date>
    </item>
  </channel>
</rss>

