  Self-testing is a procedure for characterizing quantum resources with the
minimal level of trust. Up to now it has been used as a device-independent
certification tool for particular quantum measurements, channels, and pure
entangled states. In this work we introduce the concept of self-testing more
general entanglement structures. More precisely, we present the first
self-tests of an entangled subspace - the five-qubit code and the toric code.
We show that all quantum states maximally violating a suitably chosen Bell
inequality must belong to the corresponding code subspace, which remarkably
includes also mixed states.
