学习Python中的单元测试出现问题

2024-09-29 20:23:26 发布

您现在位置:Python中文网/ 问答频道 /正文

import unittest

def get_formatted_name(first, last):

    full_name = first + ' ' + last
    return full_name.title()

class NamesTestCase(unittest.TestCase):

    def test_first_last_name(self):

        formatted_name = get_formatted_name('john', 'smith')
        self.assertEqual(formatted_name, 'John Smith')

unittest.main()

所以我对Python还是相当陌生的,这是我第一次使用unittest。我正试图使用unittest测试get_formatted_name函数,但它总是返回:

Ran 0 test in 0.00s

OK

我假设我的NamesTestCaseclass出了问题,有人看到什么问题了吗?你知道吗

谢谢。你知道吗


Tags: nametestimportselfgetreturntitledef
1条回答
网友
1楼 · 发布于 2024-09-29 20:23:26

我在我的本地服务器上试用了你的代码,效果很好

~/Documents/Python » python test.py
.
                                   
Ran 1 test in 0.000s

OK

我使用的是python2.7.14。你知道吗

相关问题 更多 >

    热门问题