Unit Test Generation: a Tokeny case study
Analyze existing code logic to auto-generate high-coverage unit test cases. Follow the recorded task, execution screenshots, actual files and verification notes.
By the Tokeny team · Windows · Tokeny 1.7.8 · gpt-6-sol
Prepare the inputs
Create a separate workspace in Tokeny, download and unpack the sample inputs, then select a model that supports tools. The sample uses synthetic data or the public sources named in the article.
- discount.mjs
Send the task to Tokeny
The original task was executed in Chinese. Copying these instructions reproduces the same task; the results below include an English report.
阅读折扣函数并编写有意义的 node:test 用例,覆盖正常、边界与异常输入,执行后保留报告。 交付文件:discount.test.mjs、test-results.txt。 验收要点: - 覆盖数量 0、折扣 0/1、非有限数与负数 - 实际 node --test 通过 这是使用合成演示输入或指定公开资料的真实操作案例。请先读取工作空间输入,再实际生成文件并自检。所有写入、脚本与临时服务限于当前工作空间;临时服务只监听 127.0.0.1,执行后关闭;不触达外部收件人、不发布、不付款、不更改系统设置,不调用子智能体。需要公开资料时可读取给定 URL。只启用完成任务必需的工具。另写 report.md(中文)和 report.en.md(英文),简洁、完整,包含输入、处理步骤、真实结果、检查方式和局限;失败或未验证部分如实记录,不能宣称成功。最终回复用中文列出产物、关键结果与待核实项。
The recorded run used an isolated demonstration workspace. Review the commands and file paths before approving operations in your own workspace.
What actually ran
The task was submitted through the Tokeny input box. An online model read the inputs and executed tools. This run covers the local sample task and its actual files. Results and checks are recorded below.
Results and verification
Input
- System under test:
discount.mjs - Function:
total(price, count, discount = 0) - Read behavior: all three arguments must be finite numbers;
priceandcountmust be non-negative;countmust be an integer;discountmust be within[0, 1]. Invalid input throwsRangeError; valid results are rounded to two decimal places.
Processing Steps
- Read
discount.mjsand the workspace environment notes. - Created
discount.test.mjsusing Node's built-innode:testandnode:assert/strict. - Added normal, boundary, and invalid-input cases covering quantity 0, discounts 0 and 1, non-finite values, negative values, type checks, and integer validation.
- Ran
node --test discount.test.mjsand saved the complete TAP output intest-results.txt.
Actual Results
- Tests: 10
- Passed: 10
- Failed: 0
- Cancelled: 0
- Skipped: 0
- The test process exited successfully; reported duration was approximately 213.5 ms.
Verification Method
- Checked the TAP summary in
test-results.txt:# tests 10,# pass 10, and# fail 0. - Read
discount.test.mjsto verify the assertions and required coverage.
Limitations
- This is a function-level test in an isolated demonstration workspace; it does not cover database, network, or UI integration.
- The implementation was not changed; the result applies only to the tested examples and the observed input contract.
- Extremely large numeric values and every possible non-numeric object/array input were not exhaustively tested.
Download and inspect the outputs
The archive contains the files created during this run. Use these checks when adapting the example to your own data.
- Reconcile the reported results against the downloadable sample inputs.
- Open the generated files and check the contents relevant to your task.
- Review the limitations and any unverified steps in the report.
