【发布时间】:2021-08-01 20:43:50
【问题描述】:
假设我有这个代码。真的不确定如何对此进行单元测试,因为它是一个 void 方法,需要用户输入,并且其中一种情况的有效答案是调用另一种方法。比如我如何测试这个?
def start():
user_Response = input(
'\n' "○ Press 1 to Enter the Main Menu" '\n'
"○ Press 2 or type 'exit' to Exit \n ")
if user_Response == str(1):
mainMenu()
elif user_Response == str(2) or user_Response.lower() == "exit":
print(
'Thank you, good bye.
exit()
else:
"Please enter a valid response."
start() ```
【问题讨论】:
-
This answer 可能对模拟标准输入和标准输出有用。
标签: python unit-testing testing