2012-07-17 97 views
0

我使用下面的代碼爲我的春行家應用程序的JUnit測試春天的JUnit文件加載問題

private static BeanFactory servicefactory = null; 
private static BookingProcessService bookingProcessService; 
@BeforeClass 
public static void setUpBeforeClass() throws Exception{ 
    try{ 
     String[] configFiles = {"applicationcontext-Service.xml","applicationcontext-Hibernate.xml","applicationContext-dao.xml"}; 
     ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(configFiles); 
     servicefactory = (BeanFactory) appContext; 
     bookingProcessService = (BookingProcessService) servicefactory.getBean("bookingProcessService");    
    }catch (Exception e){ 
     e.printStackTrace(); 
    } 
} 

雖然使用Maven構建我的項目,我得到一個名爲bookingProcessBusiness一些errors.The豆不創建可能是因爲彈簧配置文件沒有正確加載。

有人可以幫我嗎?

回答

4
  1. 請提供準確的例外,你得到

  2. 是的,你是吞嚥進一步拋,讓JUnit的知道的東西,而不是例外是錯誤的。不這樣做:

    }catch (Exception e){ 
        e.printStackTrace(); 
    } 
    
  3. 你爲什麼不使用內置Spring support for integration testing

    @RunWith(SpringJUnit4ClassRunner.class) 
    @ContextConfiguration(locations={"applicationcontext-Service.xml","applicationcontext-Hibernate.xml","applicationContext-dao.xml"}) 
    public class BookingProcessServiceTest { 
    
        @Autowired 
        private BookingProcessService bookingProcessService; 
    
    } 
    

    無膠碼,無static s。