测试代码(测试函数)

Posted aszeno

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了测试代码(测试函数)相关的知识,希望对你有一定的参考价值。

 

测试函数:

name_function.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 21:54
# @Author  : solo
# @Site    : 
# @File    : name_function.py
# @Software: PyCharm

def get_formatted_name(first,middle,last,lll):
    full_name = first +   + middle +  + last + lllc
    return full_name.title()

 

names.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 21:56
# @Author  : solo
# @Site    : 
# @File    : names.py
# @Software: PyCharm

from  name_function import get_formatted_name

print("Enter ‘q‘ at any time to quit.")
while True:
    first = input("
please give me a first name:")
    if first == q:
        break
    last = input("
please give me a last name:")
    if last == q:
        break

    get_formatted_name = get_formatted_name(first,last)
    print("	Neatly formatteb name: " + get_formatted_name + ".")

 

执行结果:

Enter q at any time to quit.

please give me a first name:jamea

please give me a last name:kason
    Neatly formatteb name: Jamea Kason.

please give me a first name:q

Process finished with exit code 0

 

 

 

单元测试和测试用例

 

代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 22:06
# @Author  : solo
# @Site    : 
# @File    : test_name_function.py
# @Software: PyCharm

import unittest
from name_function import get_formatted_name

class NamesTestCase(unittest.TestCase):
    """测试name_function.py"""
    def test_first_last_name(self):
        """能否正确的处理名字?"""
        formatted_name = get_formatted_name(janis,joplin)
        self.assertEqual(formatted_name,Janis Joplin)

unittest.main()

执行结果:

----------------------------------------------------------------------

Ran 0 tests in 0.000s

OK

 

以上是关于测试代码(测试函数)的主要内容,如果未能解决你的问题,请参考以下文章

CTS测试CtsWindowManagerDeviceTestCases模块的testShowWhenLockedImeActivityAndShowSoftInput测试fail项解决方法(代码片段

;~ 小部分AutoHotkey源代码片段测试模板2019年10月9日.ahk

这个代码片段有啥作用?

typescript Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming/angular-2/

typescript Angular最终版本的Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming

typescript Angular最终版本的Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming