【问题标题】:Python Unit Testing in Eclipse only runs one functionEclipse 中的 Python 单元测试只运行一个函数
【发布时间】:2012-02-14 15:55:33
【问题描述】:

希望这个问题有一个简单的答案。这可能是我在做的一些愚蠢的事情!

在 Eclipse 中,为以下代码运行 Python 单元测试:

import unittest
from ShipClass import *
from Graphics import *

class UnitTesting(unittest.TestCase):
    def testInit(self):
        self.screen = load_screen()
        assert load_background() == True
        print("Here!")

    def spawnShip(self):
        ship = Ship((self.screen.get_rect().x, self.screen.get_rect().y))
        self.screen.blit(ship.image, ship.rect)
        print("Here!")

        assert updateDisplay() == True

代码只输出一个“这里!”到控制台。它还说,“Ran 1 test...”等等。

为什么不运行两个测试?

感谢您的帮助。

【问题讨论】:

    标签: python eclipse unit-testing


    【解决方案1】:

    Python unittest 运行器使用方法名称前缀来查找测试。 spawnShip 未被识别为测试方法。要解决此问题,请将其命名为 testSpawnShip

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-13
      • 2013-10-30
      • 2013-02-26
      • 1970-01-01
      • 1970-01-01
      • 2014-04-25
      • 2014-03-25
      • 2010-10-13
      相关资源
      最近更新 更多