Tag tests

Latest posts for tag tests

2016-04-17 17:03:49+02:00

Embracing test failure

When I start sketching out tests for my code, I often use the test names as placeholders for the tests I know I'll want to write. I don't necessarily know when the tests get written, but for sure I know that I'm not done until all of the tests are written and pass.

That means it's not ok for me to lazily do:

class ExampleTestCase(TestCase):
    """Test case covers known acceptance criterias"""

    def test_ac1(self):
        pass

    def test_ac2(self):
        pass

Why not? Because then my first run of the unwritten tests would pass, not fail. Worse yet, I might forget to flesh out some of the test cases.

Making your tests fail

In order to make the test fail so that I know what is missing, and so that I only get the happy carrot of a passing test when it's well deserved, I instead make everything fail:

UNTESTED = "The test has not been written"

class ExampleTestCase(TestCase):
    """Test case covers known acceptance criterias"""

    def test_ac1(self):
        self.fail(UNTESTED)

    def test_ac2(self):
        self.fail(UNTESTED)

Fare thee well, my friend, and may all your tests be green when, and only when, you are done.

programming python tests