I have recently read the proof of the following theorem, i.e.,
Theorem Let $I$ be an open subset of $\mathbb{R}$. Let $f \in L^1_{\mathrm{loc}} (I)$ such that $\int_I f \varphi' =0$ for all $\varphi \in C^\infty_c (I)$. Then $f$ is constant a.e. in $I$.
Proof We fix a function $\psi \in C^\infty_c (I)$ such that $\int_I \psi = 1$. Let $w \in C^\infty_c (I)$ and $h := w - ( \int_I w) \psi$. Clearly, $h \in C^\infty_c (I)$. We define $\varphi \in C^\infty (I)$ by $\varphi (x) := \int_{-\infty}^x h(s) \, \mathrm d s$. By FTC, $\varphi' = h$. Because $\int_I h =0$, we get $\varphi \in C^\infty_c (I)$. Then $$ \begin{align*} 0 &= \int_I f \varphi' \\ &= \int_I f h \\ &= \int_I f \left ( w - \left ( \int_I w \right ) \psi \right) \\ &= \int_I \left ( f - \int_I f \psi \right) w. \end{align*} $$ Because $w$ is arbitrary in $C^\infty_c (I)$, we get $f = \int_I f \psi$ a.e. on $I$.
I would like to ask if above theorem holds in higher dimension, i.e.,
Let $\Omega$ be an open subset of $\mathbb{R}^d$. Let $f \in L^1_{\mathrm{loc}} (\Omega)$ such that $\int_\Omega f \nabla \varphi =0$ for all $\varphi \in C^\infty_c (\Omega)$. Then $f$ is constant a.e. in $\Omega$.
Thank you so much for your elaboration!