如何驗證在 dart 單元測驗中是否需要列印?
我正在為教科書撰寫示例代碼并想嘗試一下。為了簡單起見,有許多使用列印的示例。我想運行我的單元測驗以確保使用正確的輸入呼叫列印,但是在另一個 dart 檔案中匯入主函式時遇到問題。
謝謝!
uj5u.com熱心網友回復:
您可以匯入任何庫,包括帶有main方法的腳本。問題是您自己的腳本main方法會影響匯入。
解決方案是匯入帶有前綴的庫:
import "other_library.dart" as testee;
void main() {
print("Testing something");
testee.main(); // Uses a prefixed name to avoid name conflict.
print("Testing done");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/477539.html
上一篇:如何在側邊選單中向下滾動
下一篇:4輸入&動態變化變換
