I'm having trouble figuring this out and its been bothering me for a few weeks now. The solution constructs a test function in a particular way to prove the result, but I have trouble understanding how one would come up with such a construction.
The solution:
We fix $\chi \in \mathcal{D}(\mathbb{R})$ such that $\int_{\mathbb{R}} \chi(x) dx = 1$. Then any $\mu \in \mathcal{D}(\mathbb{R})$ can be written as $\mu(x) = \phi(x) + m\chi(x)$, where $m=\int_{\mathbb{R}}\phi(x)dx=0$, and there exists $\psi \in \mathcal{D}(\mathbb{R})$ such that $\psi' = \phi$.
Then for any $\mu \in \mathcal{D}(\mathbb{R}$), we have (by linearity) $$\langle f,\mu \rangle =\;...\;= \langle \langle f,\chi \rangle,\mu\rangle$$
Following @Ninad Munshi 's comment, this is my attempt: $\langle \frac{dg}{dx},\phi \rangle = -\langle g,\phi' \rangle = 0 \quad \forall \phi \in \mathcal{D}(\mathbb{R}) \implies \phi $ is the derivative of another compactly supported test function, i.e. $\phi=\psi'$ for some $\psi \in \mathcal{D}(\mathbb{R})$.
This is a construction that is used several times in distribution theory.
I think that it might be helpful to look at a more general problem first: Does every distribution have an antiderivative, i.e. if $v\in\mathcal{D}'(\mathbb{R})$ does there exist $u\in\mathcal{D}'(\mathbb{R})$ such that $u'=v$?
The answer is affirmative, but not trivial. Given $\varphi\in C^\infty_c(\mathbb{R})$ how shall we define $\langle u, \varphi \rangle$? If there exists $\psi\in C^\infty_c(\mathbb{R})$ such that $\varphi=\psi'$ then it's easy: $$\langle u, \varphi \rangle = \langle u, \psi'\rangle = -\langle u', \psi\rangle = -\langle v, \psi\rangle.$$
But that requires $\langle 1, \varphi \rangle = 0,$ which in general is not true. So how should we do when $\langle 1, \varphi \rangle \neq 0$?
The solution is to split $\varphi$ into two parts, one which is a projection onto the space of test functions for which the condition is true, and one for which the condition is false, but which is a multiple of some fixed test function $\rho$ and where the coefficient is the result of a distribution acting on $\varphi.$
So take some $\rho \in C^\infty_c(\mathbb{R})$ and set $\tilde\varphi = \varphi - \langle 1, \varphi \rangle \rho.$ Then there exists $\psi\in C^\infty_c(\mathbb{R})$ such that $\tilde\varphi=\psi'$ so $$ \langle u, \varphi \rangle = \langle u, \tilde\varphi \rangle + \langle u, \rho\rangle\langle 1,\varphi\rangle = \langle v, \psi \rangle + \langle C 1,\varphi\rangle , $$ where $C=\langle u,\rho\rangle$ is just a constant.
Now a general theorem:
Theorem: Let $T$ be a linear operator on $\mathcal{D}'$ with $\langle T u, \varphi \rangle = \langle u, T^* \varphi \rangle,$ where $T^*$ is an operator on $C^\infty_c,$ and let $n \in \mathcal{D}'$ be such that $\varphi \in T^*C^\infty_c:=\{ T^*\psi \mid \psi\in C^\infty_c \}$ if and only if $\langle n, \varphi \rangle =0.$ Then $T u=0$ if and only if $u=Cn$ for some constant $C.$
Proof: Assume $T u=0.$ Take $\rho\in C^\infty_c$ such that $\langle n, \rho \rangle=1.$ Given $\varphi \in C^\infty_c$ set $\tilde{\varphi} = \varphi - \langle n, \varphi \rangle \rho.$ Then $\langle n, \tilde{\varphi}\rangle = 0$ so $\tilde{\varphi}\in T^*C^\infty_c,$ i.e. there exists $\psi\in C^\infty_c$ such that $\tilde{\varphi}=T^*\psi$ and $$\langle u, \tilde\varphi \rangle = \langle u, T^*\psi \rangle = \langle T u, \psi \rangle = 0.$$
Thus, $$ \langle u, \varphi \rangle = \langle u, \tilde\varphi + \langle n, \varphi \rangle \rho \rangle = \langle u, \tilde\varphi \rangle + \langle u, \rho \rangle \langle n, \varphi \rangle = \langle Cn, \varphi \rangle, $$ where $C=\langle u, \rho \rangle.$
Example 1 In your question you have $T$ be the differential operator, $T u=u'$ and $T^*\varphi=-\varphi',$ and $n\equiv 1,$ i.e. $\langle n, \varphi \rangle = \int_{\infty}^{\infty} \varphi(x) \, dx.$
Example 2 With $T=x=T^*,$ i.e. $(T^*\varphi)(x)=x\varphi(x),$ and $n=\delta,$ the theorem shows that all solutions to $xu(x)=0$ are given by $u=C\delta,$ where $C$ is a constant.