我正在编写unittest以查看从命令行获取的输入是否正确存储。对不起如何设置是因为当我运行unittest时它会打开终端并且我必须在其中写入一些内容然后进入并进行测试。我想要的是编写测试用例,我可以将参数传递给unittest,自动替换终端输出,我得到结果。这是我的示例代码:
class terminal_input(cmd.Cmd):
user_database = {}
def do_add_customer(self):
""" Add a new customer to the database"""
name = input("Enter your name: ")
id = 123
user_database[id] = name
class terminal_input_test(unittest.TestCase):
def test_add_new_customer (self, name, id):
ticketing_system = terminal_input()
ticketing_system.do_add_customer()
#Do something here that name argument goes into input rather than typing it out
self.assertEqual(name,ticketing_system.user_database[id])
if __name__ == '__main__':
test_case_1 = terminal_input_test()
test_case_1.test_add_new_customer(foo, 123)