为什么我的单元测试不是 运行?
Why are my unit tests not run?
我制作了一个计算元音数量的函数(根据印刷品,它有效)。
我对单元测试有点陌生,目前当我 运行 脚本时,它并不是说 0 个测试是 运行。
我哪里做错了?
import unittest
# data = raw_input("Please type a sentence: ")
def countVowels(string):
count = 0
for char in string:
if char in 'AEIOUaeiou':
count += 1
if count % 2 == 0:
return 'even'
else:
return 'odd'
class VowelTest(unittest.TestCase):
def even(self):
self.assertEqual(countVowels('Hello'), 'even')
def odd(self):
self.assertEqual(countVowels('Hi'), 'odd')
print countVowels("Hello")
print countVowels('hi')
if __name__ == '__main__':
unittest.main()
我认为您的测试名称显示以单词 test
开头。例如:
def testAdding():
pass
def testSubtracting():
pass
我制作了一个计算元音数量的函数(根据印刷品,它有效)。
我对单元测试有点陌生,目前当我 运行 脚本时,它并不是说 0 个测试是 运行。
我哪里做错了?
import unittest
# data = raw_input("Please type a sentence: ")
def countVowels(string):
count = 0
for char in string:
if char in 'AEIOUaeiou':
count += 1
if count % 2 == 0:
return 'even'
else:
return 'odd'
class VowelTest(unittest.TestCase):
def even(self):
self.assertEqual(countVowels('Hello'), 'even')
def odd(self):
self.assertEqual(countVowels('Hi'), 'odd')
print countVowels("Hello")
print countVowels('hi')
if __name__ == '__main__':
unittest.main()
我认为您的测试名称显示以单词 test
开头。例如:
def testAdding():
pass
def testSubtracting():
pass