I'm having trouble with the theoretical definition of the p-value. Let $T$ be a test statistic with CDF $F(T)$ and supose the null hypothesis is true. If we were to reject the null hypothesis for small values of $T$ then the p-value is defined by $P:=F(T)$. But if we were to reject the null hypothesis for large values of $T$ then the p-value is defined as $P := 1-F(T)$.
What is a proof for this assertion and why is it defined as a random variable? I already know that $F(T)$ follow a Unif(0,1) distribution.
Thank you.