説明なし

test_survey.py 1.0KB

12345678910111213141516171819202122232425262728293031
  1. import unittest
  2. from survey import AnonymousSurvey
  3. class TestAnonymousSurvey(unittest.TestCase):
  4. """Tests for the class AnonymousSurvey."""
  5. def setUp(self):
  6. """
  7. Create a survey and a set of responses for use in all test methods.
  8. """
  9. question = "What language did you first learn to speak?"
  10. self.my_survey = AnonymousSurvey(question)
  11. self.responses = ['English', 'Spanish', 'Mandarin']
  12. def test_store_single_response(self):
  13. """Test that a single response is stored properly."""
  14. self.my_survey.store_response(self.responses[0])
  15. self.assertIn(self.responses[0], self.my_survey.responses)
  16. def test_store_three_responses(self):
  17. """Test that three individual responses are stored properly."""
  18. for response in self.responses:
  19. self.my_survey.store_response(response)
  20. for response in self.responses:
  21. self.assertIn(response, self.my_survey.responses)
  22. unittest.main()