Solution (source code)

= Solution

For $n\geq2$, use the unbiased residual variance $s^2=\mathrm{RSS}/(n-1)=n\widehat\sigma^2/(n-1)$. Under the null hypothesis, $(\widehat\beta-\beta_0)\sqrt{S_{xx}}/\sigma$ is standard normal and independent of $\mathrm{RSS}/\sigma^2\sim\chi^2_{n-1}$. Hence
$$
\boxed{T=\frac{(\widehat\beta-\beta_0)\sqrt{S_{xx}}}{s}\sim t_{n-1}\quad\text{under }H_0.}
$$
For a chosen significance level $\alpha$, reject the null in favor of the two-sided alternative exactly when $|T|>t_{n-1,1-\alpha/2}$, the stated upper quantile of the <Student t-distribution>. The exact two-sided p-value is $2P(t_{n-1}\geq|T_{\rm obs}|)$. This <hypothesis test> does not substitute the biased MLE for $s^2$ without correcting its factor and does not use a normal critical value when variance is unknown.