Introduction
Each test should check only one thing. This makes tests easier to understand and fix.
Jump into concepts and practice - no test required
Each test should check only one thing. This makes tests easier to understand and fix.
def test_function(): # Arrange # Act # Assert assert something == expected_value
Each test function should focus on one behavior or feature.
Use clear names to show what the test checks.
def test_add_positive_numbers(): result = add(2, 3) assert result == 5
def test_add_negative_numbers(): result = add(-1, -4) assert result == -5
def test_add_zero(): result = add(0, 5) assert result == 5
This example shows three tests. Each test checks one simple case of the add function. This way, if one test fails, you know exactly which case has a problem.
def add(a, b): return a + b def test_add_positive_numbers(): result = add(2, 3) assert result == 5 def test_add_negative_numbers(): result = add(-1, -4) assert result == -5 def test_add_zero(): result = add(0, 5) assert result == 5
Keep tests small and focused to find bugs faster.
One test = one reason to fail.
Good test names help understand what is tested.
Write tests that check only one thing.
This makes tests easier to read and fix.
Clear test names help everyone understand the test purpose.
def test_example():
x = 5
assert x == 5
assert x > 0
def test_user():
assert login('user') == True
assert update_profile('user', 'new info') == True