lundi 4 novembre 2019

Python unittest not running specified test

I'm currently working my way through Python Crash Course and have run into a problem during the testing chapter. I've went through with a comb, explained it to my imaginary rubber duck, and can't see at all where I'm going wrong.

Running the test file gives me "Run 0 tests in 0.000s" but no errors that I can see. The first block is from my file "survey.py", and the second is the test file "testSurvey.py"

Any help is hugely appreciated.

class AnonymousSurvey():

    def __init__(self, question):
        self.question = question
        self.responses = []

    def showQuestion(self):
        print(self.question)

    def storeResponse(self, newResponse):
        self.responses.append(newResponse)

    def showResults(self):
        print("The survey results are")
        for response in self.responses:
            print("-- " + response)



import unittest

from survey import AnonymousSurvey

class TestAnonymousSurvey(unittest.TestCase):
    def TestStoreSingleResponse(self):
        question = "What is your favourite language?"
        mySurvey = AnonymousSurvey(question)
        responses = ["English", "Latin", "Franglais"]
        for response in responses:
            mySurvey.storeResponse(response)

        for response in responses:
            self.assertIn(response, mySurvey.responses)

unittest.main()

Aucun commentaire:

Enregistrer un commentaire