事件強制觸發之JavaScript測試
Forced Event Triggering on JavaScript Testing
摘要
隨著網頁程式日益龐大與複雜,基於JavaScript的網頁應用快速發展,也運作於現行所有的瀏覽器。其中重要的議題是除了傳統的單元測試、功能測試來保證應用的穩定性外,也必須確保在繁瑣的非同步操作中,維繫程式的品質。但在非同步程式中,特定的呼叫次序與計時器回呼函數,會影響程式狀態與頁面被掛載的事件。我們需要自動化測試的方式,試圖進入更多的程式區塊,以確認每一個狀態的註冊事件、回呼函數功能都正常。由於非同步程式的因素,需要更繁雜的測試案例來涵蓋更多的路徑。
本論文基於動態測試,透過Chrome Devtools Protocol / DOM API和JavaScript原型複寫,監測、觸發程式執行的觸發點,透過不同的事件觸發策略觸發事件的回呼函數,藉此收集程式錯誤。我們的研究方法能在JavaScript程式中進入更多程式區塊,對比於傳統的靜態分析,在較低效能負擔的情況,獲得更多的程式涵蓋率。我們在現實環境的網頁應用中找到設計錯誤的回呼函數,如操作錯誤版本的函式庫方法、非同步資料相異常、終止條件遺失的遞迴呼叫、過早掛載的潛在危害監聽器函數。評估結果顯示,比較類似系統 Artemis,經由強制觸發事件執行,顯著提升測試的涵蓋率。
本論文基於動態測試,透過Chrome Devtools Protocol / DOM API和JavaScript原型複寫,監測、觸發程式執行的觸發點,透過不同的事件觸發策略觸發事件的回呼函數,藉此收集程式錯誤。我們的研究方法能在JavaScript程式中進入更多程式區塊,對比於傳統的靜態分析,在較低效能負擔的情況,獲得更多的程式涵蓋率。我們在現實環境的網頁應用中找到設計錯誤的回呼函數,如操作錯誤版本的函式庫方法、非同步資料相異常、終止條件遺失的遞迴呼叫、過早掛載的潛在危害監聽器函數。評估結果顯示,比較類似系統 Artemis,經由強制觸發事件執行,顯著提升測試的涵蓋率。
With the growing size and complexity of web applications, JavaScript-based web applications are rapidly evolving and operating in all existing browsers. An important issue is how to ensure the quality of the program in the cumbersome asynchronous operation. The traditional test method is to ensure the stability of the application through more fine-grained unit test and functional test. However, in the asynchronous program, the specific call sequence and the asynchronous callback function (like timer) will affect the program state and the event attached. We need to automate the testing process to try to enter more code blocks and confirm that the event and callback function are functional. Due to the asynchronous natures, more complicated test cases are needed to cover more test paths.
This research is based on dynamic testing through the Chrome Devtools Protocol, DOM API and JavaScript prototype override, monitoring and triggering the entry point of the event callback function in different strategies, thereby collecting program errors. Compared to the traditional static analysis, our research method can enter more program blocks in JavaScript programs at lower cost. We are able to find low-quality and week callback functions in real-world web applications, such as using incorrect library methods, asynchronous data dependency errors, recursive calls without termination, and potential hazard of prematurely mounted callbacks. The evaluation results reveal that compared with the similar system Artemis, our forced triggered event-based testing significantly improves the testing coverage.
This research is based on dynamic testing through the Chrome Devtools Protocol, DOM API and JavaScript prototype override, monitoring and triggering the entry point of the event callback function in different strategies, thereby collecting program errors. Compared to the traditional static analysis, our research method can enter more program blocks in JavaScript programs at lower cost. We are able to find low-quality and week callback functions in real-world web applications, such as using incorrect library methods, asynchronous data dependency errors, recursive calls without termination, and potential hazard of prematurely mounted callbacks. The evaluation results reveal that compared with the similar system Artemis, our forced triggered event-based testing significantly improves the testing coverage.