title: Spring Boot / JUnit, run all unit-tests for multiple profiles
body: <p>I have a BaseTest class which consists of several tests. Each test shall be executed for EVERY profile I list.</p>
  
  <p>I thought about using Parameterized values such as:</p>
  
  <pre><code>@RunWith(Parameterized.class)
  @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  // @ActiveProfiles("h2-test") // &lt;-- how to iterate over this?
  public abstract class BaseTest {
  
  @Autowired
  private TestRepository test;
  
  // to be used with Parameterized/Spring
  private TestContextManager testContextManager;
  
  public BaseTest(String profile) {
     System.setProperty("spring.profiles.active", profile);
     // TODO what now?
  }
  
  @Parameterized.Parameters
  public static Collection&lt;Object[]&gt; data() {
    Collection&lt;Object[]&gt; params = new ArrayList&lt;&gt;();
    params.add(new Object[] {"h2-test" });
    params.add(new Object[] {"mysql-test" });
    return params;
  }
  
  @Before 
  public void setUp() throws Exception {
    this.testContextManager = new TestContextManager(getClass());
    this.testContextManager.prepareTestInstance(this);
    // maybe I can spinup Spring here with my profile?
  }
  
  @Test
  public void testRepository() {
    Assert.assertTrue(test.exists("foo"))
  }
  </code></pre>
  
  <p>How would I tell Spring to run each test with these different profiles? In fact, each profile will talk to different datasources (in-memory h2, external mysql, external oracle, ..) so my repository/datasource has to be reinitialized.</p>
  
  <hr>
  
  <p><em>I know that I can specify @ActiveProfiles(...) and I can even extend from BaseTest and override the ActiveProfile annotation. Although this will work, I only show a portion of my test-suite. Lots of my test-classes extend from BaseTest and I don't want to create several different profile-stubs for each class. Currently working, but ugly solution:</em></p>
  
  <ul>
  <li>BaseTest (@ActiveProfiles("mysql"))
  
  <ul>
  <li>FooClassMySQL(annotation from BaseTest)
  
  <ul>
  <li>FooClassH2(@ActiveProfiles("h2"))</li>
  </ul></li>
  <li>BarClassMySQL(annotation from BaseTest)
  
  <ul>
  <li>BarClassH2(@ActiveProfiles("h2"))</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <hr>
  
  <p>Thanks</p>