Overall increases in the uptake of HIV testing in the past two decades might hide discrepancies across socioeconomic groups. We used data from population-based surveys done in sub-Saharan Africa to quantify socioeconomic inequalities in uptake of HIV testing, and to establish trends in testing uptake in the past two decades. We analysed data from 16 countries in sub-Saharan Africa where at least one Demographic and Health Survey was done before and after 2008. We assessed the country-specific and sex-specific proportions of participants who had undergone HIV testing in the previous 12 months across wealth and education groups, and quantified socioeconomic inequalities with both the relative and slope indices of inequalities. We assessed time trends in inequalities, and calculated mean results across countries with random-effects meta-analyses. We analysed data for 537 784 participants aged 15-59 years (most aged 15-49 years) from 32 surveys done between 2003 and 2016 (16 before 2008, and 16 after 2008) in Cameroon, Côte d'Ivoire, DR Congo, Ethiopia, Guinea, Kenya, Lesotho, Liberia, Malawi, Mali, Niger, Rwanda, Sierra Leone, Tanzania, Zambia, and Zimbabwe. A higher proportion of female participants than male participants reported uptake of HIV testing in the previous 12 months in five of 16 countries in the pre-2008 surveys, and in 14 of 16 countries in the post-2008 surveys. After 2008, in the overall sample, the wealthiest female participants were 2·77 (95% CI 1·42-5·40) times more likely to report HIV testing in the previous 12 months than were the poorest female participants, whereas the richest male participants were 3·55 (1·85-6·81) times more likely to report HIV testing than in the poorest male participants. The mean absolute difference in uptake of HIV testing between the richest and poorest participants was 11·1 (95% CI 4·6-17·5) percentage points in female participants and 15·1 (9·6-20·6) in male participants. Over time (ie, when pre-2008 and post-2008 data were compared), socioeconomic inequalities in the uptake of HIV testing in the previous 12 months decreased in male and female participants, whereas absolute inequalities remained similar in female participants and increased in male participants. Although relative socioeconomic inequalities in uptake of HIV testing in sub-Saharan Africa has decreased, absolute inequalities have persisted or increased. Greater priority should be given to socioeconomic equity in assessments of HIV-testing programmes. INSERM-ANRS (France Recherche Nord and Sud Sida-HIV Hépatites).