当一个方法分支到另一个方法时如何进行单元测试

以这段代码为例。如何模拟我的代码成功进入主菜单?我现在这样做的方式是,代码只是贯穿整个程序,总是无法通过测试用例。

  user_Response =  input(
        '\n' "○ Press 1 to Enter the Main Menu" '\n'
        "○ Press 2 or type 'exit' to Exit \n ")

start(user_Response)

def start(user_ Response)
    
    if user_Response == str(1):
        mainmenu()

    elif user_Response == str(2) or user_Response.lower() == "exit":
        print(
            'Thank you for stopping by today.

我试过了:


class TestMain(unittest.TestCase):

   def test_start_1(self):
       result = main.start('1')
       self.assertEquals(result,main.mainmenu())

.非常新的单元测试

a408377654 回答:当一个方法分支到另一个方法时如何进行单元测试

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/351.html

大家都在问