Unit test generator that writes and runs tests for your code
Untested code is fine until someone changes it. Give your todo.is agent a function or module and your test framework. It writes focused unit tests, including edge cases and failure paths you might skip, runs them in its workspace, and tells you which tests found real problems before you trust them.
The prompt
- Write unit tests for [CODE OR ATTACHED FILES] using [TEST FRAMEWORK]. Cover normal cases, edge cases ([EDGE CASES I CARE ABOUT]), invalid input and error handling. Mock [WHAT TO MOCK] so tests don't touch the network or real files. Use clear test names that describe the behaviour. Run the tests in your workspace, show me the results and coverage, and list any test that fails because of a real bug in my code rather than a mistake in the test. Send the test file ready to drop into my project.
What to change
- [CODE OR ATTACHED FILES]: Paste the function or attach the module, e.g. pricing.py or cart.ts.
- [TEST FRAMEWORK]: E.g. "pytest", "Jest", "Vitest", "JUnit 5", "xUnit". Or "whatever fits my project".
- [EDGE CASES I CARE ABOUT]: E.g. "empty cart, 100% discount, negative quantities, currency rounding". Or "you decide".
- [WHAT TO MOCK]: E.g. "the payment API and the clock", "database calls". Or "nothing".
Example result
- test_pricing.py for pricing.py (pytest)
- What's covered
- • Normal cases: single item, several items, quantity above 1
- • Discounts: percentage code, fixed-amount code, expired code, code below the minimum order
- • Edge cases: empty cart, 100% discount, quantity 0, very large quantities
- • Rounding: totals in cents, 0.1 + 0.2 style float traps, three-item split
- • Errors: negative quantity raises ValueError, unknown code raises InvalidCodeError
- Sample tests
- import pytest
- from decimal import Decimal
- from pricing import cart_total, InvalidCodeError
- def test_percentage_code_applies_to_subtotal():
- cart = [{"sku": "MUG", "price": Decimal("12.50"), "qty": 2}]
- assert cart_total(cart, code="SAVE10") == Decimal("22.50")
- def test_expired_code_is_rejected(frozen_today):
- frozen_today("2026-10-08")
- with pytest.raises(InvalidCodeError):
- cart_total([{"sku": "MUG", "price": Decimal("12.50"), "qty": 1}], code="SUMMER26")
- @pytest.mark.parametrize("qty", [-1, -10])
- def test_negative_quantity_raises(qty):
- with pytest.raises(ValueError):
- cart_total([{"sku": "MUG", "price": Decimal("12.50"), "qty": qty}])
- The frozen_today fixture replaces the clock, so expiry tests don't break next month.
- Results
- • 18 tests, 17 passed, 1 failed
- • Coverage of pricing.py: 96% (the only missed line is a log message)
- The failing test is a real bug
- test_fixed_discount_never_goes_below_zero: a 15.00 fixed code on a 10.00 cart returns -5.00. Your code subtracts the discount without a floor. Suggested fix: total = max(total - discount, Decimal("0")).
- To use
- • Put test_pricing.py and conftest.py (with the fixture) in your tests/ folder
- • Run: pytest -q
How to do it with todo.is
- Copy the prompt and add your code and test framework.
- Attach the module (and any helpers it imports) in todo.is or send them to your agent.
- Your agent writes the tests, runs them and reports passes, failures and coverage.
- Read the "real bug" section first, then drop the test file into your project.
- Ask for more tests on a specific path, or for a version in another framework.
Tips for a better result
- Say which framework and folder layout you use, so imports and fixtures match your project.
- Name the edge cases you worry about. Your knowledge of the business rules makes tests far more useful.
- Mock time, randomness and network calls. Tests that depend on today's date or the internet break for no reason.
- Read each failing test before fixing the code: sometimes the test assumes a rule that isn't yours.
- Ask for tests before refactoring old code, so you can change it with confidence.
unit test generator: FAQ
- What makes a good unit test? It tests one behaviour, has a name that says what should happen, runs fast and doesn't depend on the network, real files or the current date. Arrange, act, assert keeps it readable.
- Can it reach 100% coverage? It aims for the important behaviours, which usually gives high coverage. Chasing 100% often adds tests for trivial lines that don't catch bugs.
- Does it run the tests on my machine? No. It runs them in its own workspace for Python and JavaScript/TypeScript projects. You run them again in your project to confirm.
- Can it write integration or end-to-end tests too? It can write them, but they usually need your database, server or browser setup. Unit tests are the part it can fully run and check for you.
JavaScript is required to use the todo.is app.