How do I write tests correctly using unittest?

*爱你&永不变心* 提交于 2019-12-02 09:46:43

In your unittest file you have to import num_buses.

This fixes your immediate problem, but if you have defined num_buses in a1 then you have to do a1.num_buses otherwise Python will think that num_buses is a global function.

import a1
import unittest
import num_buses

class TestNumBuses(unittest.TestCase):
    """ Test class for function a1.num_buses. """
    def test_numbuses_1(self):
        actual = num_buses(75) #a1.num_buses(75) <-
        expected = 2
        self.assertEqual(actual, expected)

    # Add your test methods for a1.num_buses here.


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

Check this out: Cyber-Dojo Test - just press resume and then in test_untitled.py press the TEST button.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!