Skip to main content
Testing

Write focused tests for existing code

Point Gemini at a function and its framework, ask for the highest-value cases first (happy path, edges, failure modes), and have it flag behaviour that looks like a bug instead of testing it as correct.

提示词

Write tests for [FUNCTION] using [TEST FRAMEWORK]. Cover the happy path, edge cases, and failure modes, ordered by value. Use the existing test conventions in the repo. If any current behaviour looks like a bug, flag it instead of encoding it as expected. Code: [CODE].

替换变量

[FUNCTION]

The unit under test.

[TEST FRAMEWORK]

e.g. Vitest, Jest, pytest.

该用哪个模型

  • Gemini 3.6 FlashTest scaffolding is fast and mechanical enough for Flash.

示例输入

  • [FUNCTION] = "parsePrice(input)". [TEST FRAMEWORK] = "Vitest".

示例输出

我们只发布来自真实模型运行的示例输出。此模板尚未经过正式测试,因此不显示输出。请用上方的输入自行运行。

为何这一结构有效

  • Value-ordered cases give you the most coverage per test.
  • "Flag suspected bugs" avoids cementing wrong behaviour.

常见失败与修复

Tests pass but assert nothing meaningful.

修复:Require at least one edge case and one failure case with real assertions.

已知局限

  • Run the tests; generated tests can be shallow or wrong.

与 Google 无隶属关系,也未获其背书。Gemini、Nano Banana 和 Veo 是 Google LLC 的商标。