我目前玩springockito-annotations
,這需要@RunWith
和@ContextConfiguration
註釋才能工作。我想將這些註釋放在我的測試的超類上,但似乎無法使其工作。@ContextConfiguration不會繼承與Springockito
超類:
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})
@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = "classpath:spring/test-context.xml")
public class MyTestSuperclass {
//...
實施例的TestClass:
public class MyTest extends MyTestSuperclass {
@Inject
@ReplaceWithMock
private MyService myService;
//...
有了這個代碼,myService
不與一個模擬代替。
但是,如果我將其更改爲...
@ContextConfiguration
public class MyTest extends MyTestSuperclass {
//...
...它的工作原理。
有沒有辦法避免必須將@ContextConfiguration
添加到我的所有測試類?這可能已在更新版本的Spring
/Spring-tests
中修復?從我可以告訴它能夠繼承超類中的locations
部分而不註釋子類,但loader
部分在子類中沒有註解的情況下不起作用。我正在使用版本3.2.1.RELEASE的Spring-test
。
下面是一個示例工程中的,顯示錯誤:
http://www.filedropper.com/springockitobug
'彈簧test'因爲Spring框架3.0已經支持裝載機的繼承。所以你絕對不需要重新聲明一個空的'@ ContextConfiguration'。 Springockito實現可能存在問題。您是否願意發佈一個最小示例項目來演示此行爲(例如,在GitHub上)? –
我認爲罪魁禍首是'springockito-annotations',當註釋類有一個未註釋的超類時,我也遇到了問題,在這些情況下,@ @ ReplaceWithMock沒有工作。 – Tobb
增加了一個最小化的項目。在最小的項目中無法重現上述評論中的錯誤,所以一定是由於其他原因。 – Tobb