Spring Test Configuration Class Not Available After Every Code Change Until Project Rebuild

I have a Spring Boot application where I have a couple application properties that are only needed for integration tests, not for the actual application. I’ve added these properties to a resource file in the integration tests scope and then reference those values from variables in a @TestConfiguration class that overrides a matching @Configuration class in the main app. If I build my project and then immediately run the tests, everything works fine. But if I make code changes anywhere within the project, the next time I try to run the tests, I get “cannot find symbol” errors for the variables that are only in the test configuration.

I’ve tried creating a matching configuration with those properties in the main app and just set them to empty values, thinking maybe that would eliminate the error, as the test configuration should be picked up when running the tests. But the result is that the empty values from the main configuration file are then read by the tests.

I’ve also tried using a test configuration that has a unique name and put my test-specific variables in there. That produces the same result, where the symbols can’t be found until rebuilding.

Examples:

# main application.properties
props:
 prop-a: some value

# integration test application.properties
props:
 prop-a: override some value for tests
 test-only-prop: value only needed for tests
// main app sources
@Configuration
class ConfigClass {
   @Value("${props.prop-a}")
   public String propA;
}
// first approach

// integration test sources
@TestConfiguration
class ConfigClass {
   @Value("${props.prop-a}")
   public String propA;

   @Value("${props.test-only-prop}")
   public String testOnlyProp;
}

// test class
@Import(ConfigClass.class)
class IntegrationTests {
   @Autowired
   ConfigClass configValues;

   @Test
   void testThings() {
      var propA = configValues.propA; // this always works and uses overridden value
      var testOnlyProp = configValues.testOnlyProp; // after code changes, this only works after rebuild
   }
}
// second approach

// integration test sources
@TestConfiguration
class TestOnlyConfigClass {
   @Value("${props.test-only-prop}")
   public String testOnlyProp;
}

// test class
@Import({ConfigClass.class, TestOnlyConfigClass.class})
class IntegrationTests {
   @Autowired
   ConfigClass configValues;

   @Autowired
   TestOnlyConfigClass testOnlyConfigValues;

   @Test
   void testThings() {
      var propA = configValues.propA; // this always works and uses overridden value
      var testOnlyProp = testOnlyConfigValues.testOnlyProp; // after code changes, this only works after rebuild
   }
}

Is there something I’m doing wrong or failing to understand? Why do I need to rebuild after every code change in order to have the tests be able to read the test-only property?

If there’s nothing wrong with the code and it turns out that I’m just not understanding things correctly, is there a way to force an automatic rebuild every time integration tests are run? It’s just annoying that I have to rebuild every time because I often forget and walk away since my tests take a while, only to come back and find that the tests never ran because of this issue.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật