Assertion Roulette

Definition:

  • Occurs when a test method has multiple non-documented assertions. Multiple assertion statements in a test method without a descriptive message impacts readability/understandability/maintainability as it’s not possible to understand the reason for the failure of the test.

import unittest

airLinesCode = ['2569','2450','2340']

class Flight:
    def __init__(self,airLine,mileage):
        self.mileage = mileage
        self.airLine = airLine
        self.fullFuel = True

    def isValidAirLineCode(self):
        for airLineCode in airLinesCode:
            if(self.airLine == airLineCode):
                return True
        return False

class TestFlight(unittest.TestCase):
    def test_flight(self):
        flight = Flight('2569',1000)

        self.assertEqual(flight.mileage,1000)
        self.assertTrue(flight.fullFuel)
        self.assertTrue(flight.isValidAirLineCode())

if __name__ == '__main__':
    unittest.main(argv=['first-arg-is-ignored'], exit=False)

References:

Quality attributes

  • - Code Example

  • - Cause and Effect

  • - Frequency

  • - Refactoring