Function which integrates to $0$ against test functions with mean $0$ is constant almost everywhere. Suppose $U$ is a bounded domain in $\mathbb{R}^n$ and $u \in L^1(U)$ has the property that $$\int_{U}u\phi=0 $$ for all $\phi \in C_{c}^{\infty}(U)$ which satisfy $\int \phi = 0$. I'd like to show that $u = \bar{u}:= \frac{1}{|U|}\int_{U}u$ almost everywhere. Here was my initial approach. We have $$\int(u-\bar{u})^2 = \int u(u-\bar{u}) - \int \bar{u}(u-\bar{u}) = \int u(u-\bar{u}) .$$ Now I'm tempted to approximate $u-\bar{u}$ by smooth compactly supported mollifiers and apply something like the dominated convergence theorem to conclude that the last integral on the line above vanishes, but no straightforward argument is coming to mind. I'd appreciate if someone could help me out here.
 A: Note that every derivative $\partial_i \phi$ of a $C^\infty_c (U)$ function $\phi$ is also in $C^\infty_c(U)$ and has  $\int_U\partial_i \phi=0$. So the given condition implies that $u$ is weakly differentiable with weak gradient $\nabla u =0$ (and therefore $u\in W^{1,1}$). Now apply Weak derivatives equals zero (quoting the answer of Harald Hanche-Olsen):

If $\phi$ is a $C^\infty$ function with compact support then the convolution $u*\phi$ is also smooth, and $D(u*\phi)=(Du)*\phi=0$. So $u*\phi$ is locally constant by the usual calculus argument. Now let $\phi$ be a standard mollifier and let it converge to a delta, so that $u*\phi$ converges to $u$ a.e. (or in $L^1_{\text{loc}}$ if you prefer). So $u$ is locally constant.

Also, the comment of Caleb Nastasi in Zero weak gradient implies almost everywhere constant links to https://www.dpmms.cam.ac.uk/~cmw50/PDEEx2Sols.pdf with the following more detailed solution:

Exercise 2.4(*). Suppose $U$ is connected and $u \in W^{1, p}(U)$ satisfies $D u=0$ almost everywhere in $U$. Show that $u$ is constant almost everywhere in $U$.
[Hint: show that on any $V \subset \subset U$ the mollification $\eta_{\epsilon} \star u$ is constant for $\epsilon$ sufficiently small, and take a limit $\epsilon \rightarrow 0 .]$
Solution Let $\eta \in C_{c}^{\infty}\left(B_{1}(0)\right)$ satisfy $\eta \geq 0$ and
$$
\int_{\mathbb{R}^{n}} \eta d x=1
$$
Define $\eta_{\epsilon}(x):=\epsilon^{-n} \eta\left(\frac{x}{\epsilon}\right) .$ Fix a connected $V \subset \subset U$, and assume $\epsilon<\frac{1}{2} \operatorname{dist}(V, \partial U)$.
Recall that:
$$
u^{\epsilon}(x):=\eta_{\epsilon} \star u(x)=\int_{U} \eta_{\epsilon}(x-y) u(y) d y
$$
A standard result concerning convolutions tells us that $u^{\epsilon}$ is smooth and $D_{i} u^{\epsilon}=\left[D_{i} \eta_{\epsilon}\right] \star u .$ We compute:
$$
\begin{aligned}
D_{i} u^{\epsilon}(x) &=\int_{U} D_{i} \eta_{\epsilon}(x-y) u(y) d y=-\int_{U} \frac{\partial}{\partial y_{i}} \eta_{\epsilon}(x-y) u(y) d y \\
&=\int_{U} \eta_{\epsilon}(x-y) D_{i} u(y) d y=0
\end{aligned}
$$
Here we have used that $\eta_{\epsilon}(x-\cdot) \in C_{c}^{\infty}(U)$ and the definition of weak derivative, together with the assumption that $D u=0$. We deduce that $u^{\epsilon}$ is constant on $V$.
Now, we know that $\eta_{\epsilon} \star u \rightarrow u$ in $W^{1, p}(V)$ as $\epsilon \rightarrow 0$, and moreover the convergence is pointwise almost everywhere. A sequence of constant functions converging pointwise almost everywhere must converge to an almost everywhere constant function, so we deduce that $u$ is ae constant on $V$. Thus $u$ is ae equal to a locally constant function, but since $U$ is connected, locally constant implies constant and we're done.

