Given an i.i.d. sample drawn from a density f, we propose to test that f equals some prescribed density f0 or that f belongs to some translation/scale family. We introduce a multiple testing procedure based on an estimation of the $\mathbb{L}_{2}$ -distance between f and f0 or between f and the parametric family that we consider. For each sample size n, our test has level of significance α. In the case of simple hypotheses, we prove that our test is adaptive: it achieves the optimal rates of testing established by Ingster [J. Math. Sci. 99 (2000) 1110–1119] over various classes of smooth functions simultaneously. As for composite hypotheses, we obtain similar results up to a logarithmic factor. We carry out a simulation study to compare our procedures with the Kolmogorov–Smirnov tests, or with goodness-of-fit tests proposed by Bickel and Ritov [in Nonparametric Statistics and Related Topics (1992) 51–57] and by Kallenberg and Ledwina [Ann. Statist. 23 (1995) 1594–1608].