对python类属性的单元测试

问题描述 投票:1回答:1

假设我有一堂课:

class Player(object):
    def __init__(self):
        self.goal = ''

    @property
    def goal(self):
        return self.goal

鉴于它不可调用,是否可以在属性goal上编写单元测试?

python unit-testing python-unittest
1个回答
3
投票

怎么样:

def test_goal_property(self):
    dummy_player = Player()

    self.assertEqual(dummy_player.goal, '')     

def test_goal_property(self):
    dummy_player = Player()
    dummy_player.goal = 'something'

    self.assertEqual(dummy_player.goal, 'something')
© www.soinside.com 2019 - 2024. All rights reserved.