我正在尝试定义一个测试方法。目前我没有收到任何错误,但测试实际上并没有运行。该测试旨在确保只返回在list_first_words中的字符串的第一个单词。
import unittest
class TestSong(unittest.TestCase):
def first_words_list(self):
self.assertEqual(Song().firstwords(["hello world"]),["hello"])
if __name__ == "__main__":
unittest.main()
正在被测试的代码:
def firstwords(self,large_song_list):
all_first_words = [] # Create an empty list
for track in large_song_list:
first_word = track.trackName.partition(' ')[0]
all_first_words.append(first_word)
return all_first_words