有沒有辦法測試 console.log 整體 (Is there a way to test for console.log entires)


問題描述

有沒有辦法測試 console.log 整體 (Is there a way to test for console.log entires)

我目前正在嘗試為我的團隊擁有的應用程序實施端到端單元測試。該應用程序在網站上嵌入視頻內容並記錄播放器上發生的事件。

示例:當我們的 trackscript 服務器運行時,我們可以轉到 https://www.thrillist.com/ 當視頻正在播放時,我們可以監控播放器上發生的事件,例如靜音、快進、暫停等...並將它們記錄到控制台。

我們正在嘗試實施單元測試以檢查記錄在這些事件上的數據是否正在發生。

我們目前正在研究 BrowserStack 以檢查跨瀏覽器的兼容性,並可能使用諸如 nightwatch.js 之類的框架來編寫單元測試。

我的問題是,你可以編寫檢查控制台日誌的夜間測試嗎?


參考解法

方法 1:

Usually it's not recommended to unit test log messages: they are not part of the required behavior for a given piece of code, and should be able to change without breaking a bunch of tests.

However, if you really want to unit test log messages anyway, the recommended approach is the same as with anything you want to unit test: Wrap calls to the console messages in a separate class and use dependency injection to inject that class into your components. That way you can create spies, mocks, etc. for that dependency.

(by Michael CarnealStriplingWarrior)

參考文件

  1. Is there a way to test for console.log entires (CC BY‑SA 2.5/3.0/4.0)

#browserstack #javascript #nightwatch.js






相關問題

如何正確設置 Java/Selenium 配置以運行自動化測試? (How to properly set up Java/Selenium configuration to run automated tests?)

實習生為所有測試創建一個 BrowserStack 會話 (Intern creates one BrowserStack session for all tests)

iPhone 和 iPad 在 browserstack 上的瀏覽器測試中返回一個空白頁面 (iPhone and iPad return a blank page in browser test on browserstack)

Intern Runner 測試結果未顯示瀏覽器信息 (Intern Runner Test Results Not Showing Browser Info)

有沒有辦法測試 console.log 整體 (Is there a way to test for console.log entires)

Browserstack - 無法在移動設備上使用 browser.get (Browserstack - Not able to use browser.get on mobile devices)

使用 geb-spock 在瀏覽器堆棧的名稱功能(會話)上傳遞測試用例名稱 (Pass test case name on name capability (session) of browserstack, using geb-spock)

如何通過 Appium 使用 java 運行 browserstack 檢查元素? (How to run the browserstack inspected element with java through Appium?)

BrowserStack + Protractor + TravisCi 和安全的本地主機服務器 - 配置 (BrowserStack + Protractor + TravisCi and secure localhost server - configuration)

無法使用本地 BrowserStack、BrowserMobProxy 嵌入模式和使用 java 的 Selenium 3.x 捕獲瀏覽器網絡日誌 (Unable to capture browser network logs with BrowserStack local, BrowserMobProxy embedded mode and Selenium 3.x using java)

為防火牆後的網站運行 BrowserStackLocal 的問題 (Issues running BrowserStackLocal for website behind firewall)

BrowserStack 和 Azure 集成和運行測試 (BrowserStack and Azure integration and Run Tests)







留言討論