2012-03-09 22 views
0

運行我的我的測試類春/ Junit的訪問同級類

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(locations = {"classpath:eq-mo-dcc-context-block.xml"}) 

public class SpringTest { 

@Autowired 
private DateUtils dateManager; 

@Autowired 
private RegionFilter filter; 

@Autowired 
private ApplicationContext appContext; 

@Test 
public void test_This() 
{ 
    Object obj = appContext.getBean("BlockTransformer"); 
    BlockTransformer Trans = (BlockTransformer) obj; 


} 

一切都非常早期階段但該發生的配置文件中的問題,從其他的Maven模塊/項目訪問豆。不過,我擁有src/test/resources下的所有xml,所以它可以獲取xml。然而,當試圖拿起類文件,我得到:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [dcc.mdp.DefaultMessageListener] for bean with name 'BlockMessageListener' defined in class path resource [eq-mo-dcc-context-block.xml]; nested exception is java.lang.ClassNotFoundException: dcc.mdp.DefaultMessageListener 

該類駐留在同級Maven的模塊中,但不能從測試類回升。如何讓班級意識到自己以外的其他模塊的班級?

回答

2

一個Maven模塊不主動「知道」同父項目下的其他模塊東西,所以你要包含類的同級模塊需要被列爲包含您的測試類的模塊中的依賴關係。

+0

你需要明確定義的依賴來運行這個測試套件。 – dharam 2012-03-10 06:18:02