我如何进行单元测试?它是什么样子的?

时间:2012-12-03 16:35:59

标签: python-3.x

def abn_abc(voteslist):
    sums = {}
    for vote in votes:
        if vote in sums:
            sums[vote] += 1  
        else:
            sums[vote] = 1
    return tally_ballots(sums)

如何为此功能编写单元测试?

1 个答案:

答案 0 :(得分:1)

这样的事情:

import unittest
from wherever import abn_abc

class AbnAbcTest(unittest.TestCase):

    def test_abn_abc(self):
        list_for_testing with = [<insert list here>]
        self.assertEqual(abn_abc(list_for_testing_with), <expected result>)

if __name__ == '__main__':
    unittest.main()

Here's the documentation