How to Generate Unit Tests and Find the Edge Cases That Matter
Learn boundary value analysis and equivalence partitioning, then turn a function into edge cases and a Jest, Vitest, node:test or pytest skeleton.

How to Generate Unit Tests and Find the Edge Cases That Matter
Most bugs that escape into production are not exotic. They hide in the inputs nobody thought to try: an empty array, a price of zero, a name with an emoji in it, a string made only of spaces. Writing the first tests for a function is therefore less about typing assertions and more about asking good questions. This guide explains the two classic techniques testers use to pick those questions, and shows how to apply them quickly with a browser-based assistant.
Equivalence partitioning and boundary values
Equivalence partitioning starts from a simple idea: many inputs behave the same way, so you do not need to test all of them. For a function that accepts an age, every value from 18 to 64 might follow one path, values below 18 another, and values of 65 or more a third. Each group is a partition, and one representative from each is usually enough.
Boundary value analysis then looks at the edges between partitions, because that is where off-by-one mistakes live. If the rule changes at 18, you test 17, 18 and 19. If a list can be empty, you test zero items, one item and many items. For numbers you also think about negatives, fractions, very large values and special values such as NaN. For text, you consider the empty string, whitespace, accented characters, emoji and very long input.
Both techniques appear in the ISTQB testing syllabus.
Why the expected value is the hard part
A tool can look at code and tell you that a parameter is divided by something, so zero is worth trying. What it cannot know is what the function should return in that situation. If you copy today's output into the assertion, you lock today's bugs into the test suite. The right expected value comes from the specification, the ticket or your own judgement. Keep that in mind whichever method you use to write tests.
Generating tests step by step
Open the Unit Test Generator Assistant and follow this flow.
- Paste the code. Put one or more JavaScript, TypeScript or Python functions into the editor. If there are several, choose the one you want from the function list.
- Pick the framework and import path. Choose Vitest, Jest, node:test or pytest, and set the path the test file should import from.
- Review the Edge cases list. The assistant guesses each parameter's kind from type annotations, default values, names and how the body uses it. It then varies one parameter at a time and adds cases suggested by the body, such as division, indexing, parsing, regular expressions, thrown errors and async calls. Each case comes with a short reason. Untick anything that does not apply.
- Open Test skeleton. Every selected case becomes one test with a comment explaining why it exists. Expected values are left as TODO on purpose. Copy or download the file and fill them in.
- Optionally use the AI tab. After you read the size notice and press Load the AI model, a small coding model (about 555 MB, downloaded once and cached) runs on your device and can draft complete tests, including expected values, from the same case list.
A worked example
Suppose you have parsePrice(text: string, currency = "EUR"). It strips currency symbols, parses a float and throws when the input is empty or not a number.
The assistant recognises text as a string and currency as a string with a default. From the parsing and the throw in the body it adds cases for invalid input and non-numeric text. The resulting list includes the empty string, a string of spaces, currency omitted, a non-numeric value, regex special characters and the error path, along with others such as accented text and very long input. The Vitest skeleton imports parsePrice and contains one test per case, each with a TODO where the expected value belongs.
Your job is now to decide, for example, whether " " should throw or return zero. That is a product question, and a test makes the answer stable.
Tips and common mistakes
- Do not keep every case. Untick cases that make no sense for your domain.
- Test the omitted default. Parameters with defaults are often only tested with explicit values, and the default branch quietly breaks.
- Mock input and output. When the assistant flags network or file access, replace those calls with mocks so tests are fast and deterministic.
- Review AI drafts line by line. The local model is small. It can guess wrong expected values, invent helper functions or misread intent. Run the generated tests, read every failure, and correct the draft rather than trusting it.
Limits
Function parsing is pattern-based rather than a full compiler, so unusual syntax, decorators or overloaded signatures can be misread, and languages other than JavaScript, TypeScript and Python get only basic support. The tool never runs your code and does not measure coverage. Expected values in the skeleton are intentionally blank. The optional AI model is small, needs a recent browser and a few gigabytes of memory, and its output is a draft that must be reviewed and executed in your own project before you rely on it.



