• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 基于 JUnit 使用 Feed4JUnit 實現數據與代碼分離的測試(3)

    發表于:2012-10-09來源:IBM作者:萬書吉點擊數: 標簽:junit
    清單 6 為在方法上聲明 @Database: 清單 6. 在方法上聲明 @Database /* * Feed4JUnit - Get Data from Database, only the specified method can use the database data */@RunWith(Feeder.class)p

      清單 6 為在方法上聲明 @Database:

      清單 6. 在方法上聲明 @Database

    				 
    /*
     * Feed4JUnit - Get Data from Database, 
     only the specified method can use the database data
     */
    
    @RunWith(Feeder.class)
    public class F4JfromDB_Method {
    	@Test
    	@Database(
    			id = "testdb", 
    			url = "jdbc:db2://localhost:50000/SAMPLE", 
    			driver = "com.ibm.db2.jcc.DB2Driver", 
    			user = "db2admin", 
    			password = "db2admin")
    	@Source(id = "testdb", selector = "select * from TEST")
    	public void testAccessCheck(String userName, String pw, String expected) {
    		Boolean bSucess = UserAccess.accessCheck(userName.trim(), pw.trim());
    		assertEquals(expected.trim(), bSucess.toString());
    
    	}
    }
    
    

      測試運行過程中,通過 url,driver 等信息建立數據連接,通過 selector 發出數據請求,最后完成查詢并把數據傳遞給測試方法,數據在傳遞給方法的時候,會按數據表的列的順序與參數進行匹配,運行結果與圖 4 類似。

      自定義數據源

      除了 CSV,Excel 和數據庫的數據源外,Feed4JUnit 還提供自定義數據源,以滿足不同用戶的需求,用戶同樣可以通過封裝 JUnit 4 提供的參數化測試的方法來完成數據源自定義,所有這里作者不再詳述,用戶可以封裝并取得不同的數據源的數據,傳遞給 Feed4JUnit 的相應接口,來完成數據源的自定義。

      結束語

      本文通過對比介紹和簡單易懂的實例全面講解了 Feed4JUnit 對數據與代碼分離的測試支持。通過提供簡單的注釋,Feed4JUnit 使用戶能夠極其方便的實施數據與代碼分離的測試,極大地增強了 JUnit 測試框架的易用性。 相信您已經在本文的敘述中看到它的優點。同時,本文所敘述的僅僅是 Feed4JUnit 提供的測試增強功能的一部分,Feed4JUnit 同時還提供了大量數據的隨機測試和等價類測試等眾多功能,如果您感興趣可以自行參考。

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>