How to use the Unit Test Generator.
Unit tests should express expected behavior and meaningful boundaries. Do not simply reproduce the implementation's formula in the test.
Make the workflow fit your task.
Define expected behavior from the function's contract and select meaningful ordinary, boundary and failure cases. Use known outcomes or independent fixtures, avoiding assertions that merely repeat the implementation's calculation.
- What you provide
- Function implementation and test framework.
- What you get
- Meaningful tests covering behavior and boundary cases.
See the input and the result.
Illustrative input and output · a teaching example, not a live WebAct run
Example input
Write pytest tests for calculator.add(a, b). It returns the sum of two integers. Required cases: positive values, zero, negative values.
Completed example
# test_calculator.py
import pytest
from calculator import add
@pytest.mark.parametrize("a,b,expected", [(2, 3, 5), (0, 0, 0), (-2, 3, 1)])
def test_add(a, b, expected):
assert add(a, b) == expected
Run in the project with pytest installed: python -m pytest test_calculator.pyLoad this input into the prompt, then copy it to WebAct to try the task. Your result may differ from the illustration.
Decisions and troubleshooting.
Should a generated unit test duplicate the function's formula?
Use independently known expectations where possible. Repeating the same mistake in the test can make an incorrect implementation appear verified.
Why do all tests pass while the real failure remains?
Check whether the tests cover the failing condition and actual contract. A broad count of tests does not establish relevant coverage.
Reference for this workflow.
Try it with your own source.
Replace the example with your material in the task prompt. Keep the requirements you need, then copy the task into WebAct.
Customize and copy the task ↑