Automate unit test execution early in development
Preconditions (2)
✅ Expected Result: The unit test runs successfully and confirms the function returns the expected output for input 5
def multiply_by_two(x): return x * 2 def test_multiply_by_two(): result = multiply_by_two(5) assert result == 10, f"Expected 10 but got {result}" if __name__ == "__main__": import pytest pytest.main([__file__])
This script defines a simple function multiply_by_two that doubles the input.
The test function test_multiply_by_two calls this function with input 5 and asserts the output is 10.
Running the test immediately after writing the function follows the shift-left testing idea: testing early in development to catch issues quickly.
The assertion includes a helpful message if it fails.
The pytest.main call allows running the test by executing the script directly.
Now add data-driven testing with 3 different inputs (2, 5, 10) and expected outputs
shift-left testing?shift-left testing?Development Start -> Code Review -> Unit Testing -> Integration Testing -> Release
shift-left testing approach?Pass the test and this pattern moves unknown