  We give an explicit construction of test vectors for $T$-equivariant linear
functionals on representations $\Pi$ of $GL_2$ of a $p$-adic field $F$, where
$T$ is a non-split torus. Of particular interest is the case when both the
representations are ramified; we completely solve this problem for principal
series and Steinberg representations of $GL_2$, as well as for depth zero
supercuspidals over $\mathbf{Q}_p$. A key ingredient is a theorem of Casselman
and Silberger, which allows us to quickly reduce almost all cases to that of
the principal series, which can be analyzed directly. Our method shows that the
only genuinely difficult cases are the characters of $T$ which occur in the
primitive part (or "type") of $\Pi$ when $\Pi$ is supercuspidal. The method to
handle the depth zero case is based on modular representation theory, motivated
by considerations from Deligne-Lusztig theory and the de Rham cohomology of
Deligne-Lusztig-Drinfeld curves. The proof also reveals some interesting
features related to the Langlands correspondence in characteristic $p$. We show
in particular that the test vector problem has an obstruction in characteristic
$p$ beyond the root number criterion of Waldspurger and Tunnell, and exhibits
an unexpected dichotomy related to the weights in Serre's conjecture and the
signs of standard Gauss sums.
