import unittest from survey import AnonymousSurvey
class TestSurvey(unittest.TestCase): """争对AnonymousSurvey类的测试""" def setUp(self): """创建一个调查对象和一组答案,供使用的测试方法使用""" question = "what language did you first learn to speak?" self.my_survey = AnonymousSurvey(question) self.responses = ["English", "Spanish", "Mandarin"]
def test_store_single_response(self): """测试单个答案存储""" # question = "what language did you first learn to speak?" # my_survey = AnonymousSurvey(question) self.my_survey.store_responses(self.responses[1])
def test_store_three_responses(self): """测试三个答案存储""" # question = "what language did you first learn to speak?" # my_survey = AnonymousSurvey(question) # responses = ["English", "Spanish", "Mandarin"] for response in self.responses: self.my_survey.store_responses(response)
for response in self.responses: self.assertIn(response, self.my_survey.responses)