Two rather similar tests are available to us: the one-sample z-test and the one-sample t-test. You shall choose one of them, depending on a handful of factors such as, for example, the normality of the population, the number n of observations or whether the standard deviation of the population is a known factor. Note that there is a certain degree of flexibility when it comes to the choice of the test and we will also discuss it below.

In brief, one should use a z-test in cases where:

However, one should use a t-test in cases where:

On top of that, you should know that such tests are performed when variable are continuous (or considered continuous) and the data are independent (meaning that the data are not related to each other in any way, or that each subject in the study gave no more than one sample data).

How flexible is this?

Well… this is a subjective topic. Here are some tips that could fit many cases:

So, in a way, it seems like you would run a z-test only if you know the population standard deviation, the sample size is moderate to large (n > 30) and normality is assumed. For the rest, the t-test will save you.