🧪 Unit Test Generator
Paste a function or module and get a runnable unit-test suite covering the happy path, boundaries, invalid inputs and error paths.
- Runnable, not pseudo-code. Real imports, setup and assertions — paste into your repo and run.
- Edge cases you'd miss. Boundaries, invalid input and error paths, not just the happy path.
- Your framework. pytest, Jest, JUnit — or the idiomatic default for your language.
See the quality — a real example
Sample only · no credits usedInput — function under test
Framework: pytest
def apply_discount(price, percent):
"""Return price after a percent discount, rounded to 2dp."""
if price < 0:
raise ValueError("price must be non-negative")
if not 0 <= percent <= 100:
raise ValueError("percent must be 0..100")
return round(price * (1 - percent / 100), 2) Output — generated test suite
import pytest
from pricing import apply_discount
def test_basic_discount():
assert apply_discount(100.0, 20) == 80.0
def test_rounds_to_two_dp():
assert apply_discount(9.99, 15) == 8.49
def test_zero_percent_is_unchanged():
assert apply_discount(50.0, 0) == 50.0
def test_full_discount_is_zero():
assert apply_discount(50.0, 100) == 0.0
def test_negative_price_raises():
with pytest.raises(ValueError):
apply_discount(-1.0, 10)
@pytest.mark.parametrize("p", [-5, 101])
def test_percent_out_of_range_raises(p):
with pytest.raises(ValueError):
apply_discount(100.0, p) Cases covered
- test_basic_discount — happy path, 20% off 100
- test_rounds_to_two_dp — rounding to 2 decimal places
- test_zero/full_discount — boundaries at 0% and 100%
- test_negative_price_raises — invalid input error path
- test_percent_out_of_range_raises — parametrized −5 and 101
Note: import path assumed to be pricing — adjust to your module. We flag assumptions instead of guessing silently.
Sign in to use this tool
Sign in to use (30 free points on signup). Signed-in users run every tool on their account points — nothing to paste.
Sign in →