簡體   English   中英

在JUnit測試用例中的@ContextConfiguration中指定類加載順序

[英]Specifying classes loading order in @ContextConfiguration in JUnit test cases

我使用junit 4.11和spring-test-4.1.5編寫集成測試用例。 我正在使用@ContextConfiguration批注來加載配置。

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes ={ApplicationConfig.class,SpringConfiguration.class }, initializers = {CustomProfileResolver.class, AppInitializer.class}, loader = SpringApplicationContextLoader.class)

如您所見,我正在使用兩個配置類。 我面臨的問題是我想在ApplicationConfig.class之前加載SpringConfiguration.class 我嘗試撤銷訂單,但沒有奏效。 這里既沒有指定@order。

那么如何訂購這些配置類的加載,是否可能?

@ContextConfiguration及其支持類(例如, MergedContextConfigurationAnnotationConfigContextLoaderAbstractTestContextBootstrapper等)旨在保留通過@ContextConfigurationclasses屬性聲明的@Configuration類的原始排序。

因此,如果您可以驗證證明反轉SpringConfigurationApplicationConfig類的順序不會導致SpringConfiguration處理SpringConfiguration ,那么您在Spring中發現了一個錯誤。

如果您發現了錯誤,請在JIRA中報告。

謝謝,

山姆

使用@ContextHierarchy

@ContextHierarchy({
   @ContextConfiguration(classes = {SpringConfiguration.class}),
   @ContextConfiguration(classes = {ApplicationConfig.class})
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM