I am creating a project utilizing the new Spring configurations. I have a base class which holds a few properties:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {Basic.class, Protected.class})
public class BaseTest {
@Autowired(required = false) protected String userName;
@Autowired(required = false) protected String password;
@Autowired protected String baseURL;
@Test
public void outputData() {
System.out.println("UserName: " + userName + " Password: "
+ password + "Base URL: " + baseURL);
}
}
@ActiveProfiles("default,protected")
public abstract class ProtectedTest extends BaseTest
{
@Autowired protected String userName;
@Autowired protected String password;
}
@Configuration @Profile("default")
public class Basic {
@Bean public String baseURL() { return "http://www.baseURL.com"; }
}
@Configuration @Profile("protected")
public class Protected {
@Bean public String userName() { return "userName"; }
@Bean public String password() { return "password"; }
}
However, when I go to run my protected tests I receive a notification that the base URL is not wired in properly. Since it extends the BaseTest, and has both profiles active, why am I not receiving the baseURL bean?
It has to be
@ActiveProfiles({"default","protected"}), in your case it will assume that the profile by namedefault, protectedis active, notdefaultandprotectedOne more thing is that annotation in base class
BaseTestis not derived by theProtectedTest, so you will again need to put@RunWithand@ContextConfigurationfor your test to run