DELAPARRA
Index
Color
NL
Category: Core glossary

Stub

Explained by Updated

What is Stub?

Stub: A simplified replacement for a dependency in testing — it returns hardcoded responses without executing real logic. Similar to a mock, but stubs typically focus on providing canned answers rather than verifying calls. A stub is a simple stand-in for a real dependency in a test. It returns fixed answers without doing real work, so the code under test can run in isolation.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Stub

How is Stub used in practice?

A stub for a payment gateway might always return "approved", so you can test what your checkout does after a successful payment without calling a real payment provider or spending money.

What should you keep in mind with Stub?

The difference from a mock is focus. A stub provides answers; a mock also checks how it was called, such as whether charge() was called exactly once with the right amount. Laravel offers fakes like Mail::fake() and Http::fake() that combine both. Use stubs for external services and slow dependencies, and keep tests that exercise real database logic against a real test database.

At a glance

CategoryCore glossary
Explained by
Updated

More Core glossary terms

All terms starting with S

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.