function signature
The name, parameters and their order that define how a function must be called.
In more detail
Callers, replacements and test doubles must match it exactly, or calls will not compile or will fail. Documentation tools usually print the signature first because it answers most questions about a function.
Examples
func Getenv(key string) stringIn this course: A test double must have the same signature as the thing it replaces, or it will accept calls the real one would reject. unittest.mock's autospec copies the real signature so a wrong call fails the test.Related terms
- function — A named, reusable block of code that takes inputs, called arguments, and can return a result.
- multiple return values — A Go function returning more than one result at once, most often a useful value together with an error.
- go doc — The go subcommand that prints the documentation for a package, function or type from the toolchain you have installed.
- autospec — A unittest.mock feature that builds a mock with exactly the same methods and signatures as a real class.
- mock — A test double that stands in for a real dependency and checks that the code under test calls it in the expected way.
- test double — Any object that replaces a real dependency in a test: a stub returns canned data, a fake is a small working implementation, and a mock checks interactions.
- type annotation — A type written explicitly after a name with a colon, such as name: string, to tell the compiler what a value must be.
- Parameters<T> — The utility type that gives a function type's parameter list as a tuple, such as [orderId: string, priority: boolean].
- ReturnType<T> — The utility type that gives the return type of a function type T.
Taught in
- Installing the Go Toolchain — Concurrent Systems Programming with Go
- Pointers and Memory — Concurrent Systems Programming with Go
- Fakes, Stubs, Mocks And Spies — Automated Testing, TDD & Quality Engineering
- Type Annotations, Type Inference And Contextual Typing — Production TypeScript
- void, undefined And null: Exact Optional Property Types — Production TypeScript
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Optional Properties, Readonly And Index Signatures — Production TypeScript
- Custom Type Predicates: Functions Returning is Type — Production TypeScript
- Assertion Signatures: asserts condition And Invariants — Production TypeScript
- Exhaustive Narrowing With never In Production Handlers — Production TypeScript
- Why Generics: Functions, Identities And Type Variables — Production TypeScript
- Generic Interfaces, Classes And Type Aliases — Production TypeScript
- Default Generic Arguments And Multi-Type Parameters — Production TypeScript
- Union Utilities: Exclude, Extract, NonNullable And Awaited — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript