单元测试用例

import unittest

def login(username=None, password=None):
    """登录"""
    if (not username) or (not password):
        # 用户名或者密码为空
        return {"msg": "empty"}

    if username == 'yuz' and password == '123456':
        # 正确的用户名和密码
        return {"msg": "success"}

    return {"msg": "error"}


class TestLogin(unittest.TestCase):

    def test_01_empty(self):
        """用户名和密码都为空"""
        username = None
        password = None
        expect_response = {"msg": "empty"}
        actual_response = login(username,password)
        self.assertTrue(expect_response==actual_response)

    def test_02_username_empty(self):
        """用户名为空,密码不为空"""
        username = None
        password = '123456'
        expect_response = {"msg": "empty"}
        actual_response = login(username,password)
        self.assertTrue(expect_response==actual_response)

    def test_03_password_empty(self):
        """用户名不为空,密码为空"""
        username = None
        password = '123456'
        expect_response = {"msg": "empty"}
        actual_response = login(username, password)
        self.assertTrue(expect_response == actual_response)

    def test_04_login_success(self):
        """登录成功"""
        username = 'yuz'
        password = '123456'
        expect_response = {"msg": "success"}
        actual_response = login(username, password)
        self.assertTrue(expect_response == actual_response)

    def test_05_username_error(self):
        """用户名错误,密码正确"""
        username = 'jojo'
        password = '123456'
        expect_response = {"msg": "error"}
        actual_response = login(username, password)
        self.assertTrue(expect_response == actual_response)

    def test_06_password_error(self):
        """用户名正确,密码错误"""
        username = 'yuz'
        password = '12345678'
        expect_response = {"msg": "error"}
        actual_response = login(username, password)
        self.assertTrue(expect_response == actual_response)

 

posted @ 2020-05-25 11:39  silenceljj  阅读(134)  评论(0)    收藏  举报