pestphp/pest · error · TestDescriptionMissing
A test in [%s] is missing its description. Please give every
Error message
A test in [%s] is missing its description. Please give every test a description.
What it means
Every Pest test needs a human description. When TestCaseFactory::addMethod receives a method whose description is null (a test closure registered without a name), it throws TestDescriptionMissing, naming the file. The run aborts at load time so an anonymous test can never silently disappear from the suite.
Source
Thrown at src/Factories/TestCaseFactory.php:183
$methodsCode
}
PHP;
eval($classCode);
} catch (ParseError $caught) {
throw new RuntimeException(sprintf(
"Unable to create test case for test file at [%s]. \n %s",
$filename,
$classCode
), 1, $caught);
}
}
public function addMethod(TestCaseMethodFactory $method): void
{
if ($method->description === null) {
throw new TestDescriptionMissing($method->filename);
}
if (array_key_exists($method->description, $this->methods)) {
throw new TestAlreadyExist($method->filename, $method->description);
}
if (
$method->closure instanceof \Closure &&
new \ReflectionFunction($method->closure)->isStatic()
) {
throw new TestClosureMustNotBeStatic($method);
}
if (! $method->receivesArguments()) {
if (! $method->closure instanceof \Closure) {
throw ShouldNotHappen::fromMessage('The test closure may not be empty.');
}View on GitHub (pinned to 1af74a215c)
Solutions
- Give every test a description string: test('creates a user', function () { ... });
- If you build tests dynamically, ensure the description variable is always a non-empty string before calling test()/it().
- Adopt it()/test() with meaningful names — the description is also the failure output, so a missing one hides failures.
Example fix
// before
test(function () {
expect(1)->toBe(1);
});
// after
test('one is one', function () {
expect(1)->toBe(1);
}); Defensive patterns
Strategy: validation
Validate before calling
// in shared helpers that create tests programmatically:
function testName(string $description, Closure $closure): void
{
if (trim($description) === '') {
throw new InvalidArgumentException('Test description is required');
}
test($description, $closure);
} Prevention
- Always pass a description string as the first argument to test()/it().
- Wrap programmatic test creation in helpers that validate the description.
- Code-review rule: a bare test(function...) with no title never merges.
When it happens
Trigger: Calling test() with only a closure (no string first argument); constructing tests programmatically through the factories/API without setting a description; a helper that wraps test() and forgets to forward the description argument.
Common situations: Copy-pasting a test() call and deleting the string; writing tests through custom helper layers or plugins; migrating PHPUnit method-style tests where names came from method names, not strings.
Related errors
- A test named [%s] already exists in [%s]. Please give this t
- No sequence expectations defined.
- Test closures may not be static. Please remove the [static]
- The test [%s] in [%s] expects [%d] argument(s) ([%s]), but n
- The test directory [%s] does not exist.
AI-assisted analysis of pestphp/pest@1af74a215c (2026-08-21).
Data as JSON: /api/errors/90d134d66d1d07af.
Report an issue: GitHub.