0
0
Testing Fundamentalstesting~10 mins

Shift-left testing in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test simulates a simple software development process where testing starts early (shift-left). It verifies that bugs are caught early during development rather than later in production.

Test Code - unittest
Testing Fundamentals
class SoftwareDevelopmentProcess:
    def __init__(self):
        self.code_written = False
        self.tests_run = False
        self.bugs_found = 0

    def write_code(self):
        self.code_written = True

    def run_tests_early(self):
        if not self.code_written:
            raise Exception("Cannot test before code is written")
        self.tests_run = True
        # Simulate finding bugs early
        self.bugs_found = 2

    def deploy(self):
        if not self.tests_run:
            # Bugs found late
            self.bugs_found = 5

import unittest

class TestShiftLeft(unittest.TestCase):
    def test_shift_left(self):
        process = SoftwareDevelopmentProcess()
        process.write_code()
        process.run_tests_early()
        process.deploy()
        # Assert bugs found early are fewer than if tested late
        self.assertLess(process.bugs_found, 5)

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Create SoftwareDevelopmentProcess instanceNew process object with no code written, no tests run, zero bugs found-PASS
2Call write_code() to simulate writing codeCode written flag set to True-PASS
3Call run_tests_early() to simulate early testingTests run flag set to True, bugs_found set to 2Verify tests_run is True and bugs_found is 2PASS
4Call deploy() to simulate deploymentSince tests_run is True, bugs_found remains 2Verify bugs_found is less than 5PASS
5Assert bugs_found < 5 to confirm early testing effectivenessbugs_found is 2assertLess(2, 5) passesPASS
Failure Scenario
Failing Condition: run_tests_early() is not called before deploy(), so bugs_found remains 5
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about bugs when testing is done early?
AFewer bugs are found compared to late testing
BMore bugs are found compared to late testing
CNo bugs are found at all
DBugs found are the same as late testing
Key Result
Starting testing early in the development process helps catch bugs sooner, reducing the number of bugs found later and improving software quality.