Generating Tests with CodeLogician
Once CodeLogician understands system behavior, it can generate high-coverage test cases automatically.
Instead of writing tests manually, you can ask Claude Code to derive them directly from the reasoning results — each test targets a distinct behavioral region.
Setup
If Claude Code doesn't already know about CodeLogician, start with:
Learn how to use codelogician by running
codelogician doc --help
Example: Fee Calculation
You have a Python function:
def calculate_fee(method: str, amount: float) -> float:
if method == "card":
return 0.029 * amount + 0.30
elif method == "bank_transfer":
return 0.008 * amount + 1.50
else:
return 0.0Ask Claude Code:
Use CodeLogician to generate test cases for the calculate_fee function.
What Happens
Claude Code will:
- Translate the function into an IML model
- Run region decomposition to identify all behavioral regions
- Generate a test case for each region using
codelogician eval gen-test - Return the tests in Python
Example output:
def test_card_fee():
assert calculate_fee("card", 100.0) == 3.2
def test_bank_transfer_fee():
assert calculate_fee("bank_transfer", 100.0) == 2.3
def test_unknown_method_fee():
assert calculate_fee("crypto", 100.0) == 0.0
def test_card_zero_amount():
assert calculate_fee("card", 0.0) == 0.3
def test_bank_transfer_small_amount():
assert calculate_fee("bank_transfer", 1.51) == 1.5108What Makes These Tests Different
Generated tests are:
- Grounded in real system behavior — each test covers a distinct behavioral region
- Boundary-aware — tests target the exact inputs where behavior changes
- Complete — every reachable execution path has at least one test
This is fundamentally different from LLM-generated tests, which sample likely scenarios but may miss critical boundaries.
Why This Matters
Combining code generation with logical reasoning allows developers to move from:
manually written tests that cover obvious cases
to
mathematically derived tests that cover all behavioral regions.
This is especially valuable for systems where missed edge cases have real consequences — payments, compliance, access control, and trading logic.