您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
junit測試ssh項目
作者:網(wǎng)絡轉載 發(fā)布時間:[ 2014/1/23 11:30:35 ] 推薦標簽:測試 ssh框架 單元測試

測試ssh框架的項目,需要加載spring配置文件applicationContext.xml,數(shù)據(jù)庫連接的文件hibernate.xml。此項目中的hibernate文件整合到了spring配置文件中。

上篇日志<junit>提到BeforeClass是“所有測試方法執(zhí)行之前首先執(zhí)行此方法,可用于數(shù)據(jù)庫連接,加載配置文件等” ,所以將加載spring配置文件的代碼寫在這里,但是BeforeClass下寫的函數(shù)得是靜態(tài)的

public class userservicetest {
 
   public static UsersService usersService;
  @BeforeClass
  public staticvoid onSetUpBeforeTransaction() throws Exception {
     ApplicationContext context = new FileSystemXmlApplicationContext(
          new String[ ] {
            "/WebRoot/WEB-INF/applicationContext.xml"             
            }
        );      
     usersService = (UsersService) context.getBean("usersService");
      }
   @Test
  public void testfindUserByAccountNames() {
  String userId="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
 
  try {
            String realname= usersService.findUserByAccountNames(userId);          
            assertThat(realname, is("管理員"));         
            Assert.assertEquals("管理員", realname);
        } catch (CRUDException e) {
            e.printStackTrace();
        }
 }
}

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd