The ongoing coevolutionary struggle between hosts and pathogens, with hosts evolving to escape pathogen infection and pathogens evolving to escape host defences, can generate an 'arms race', i.e., the occurrence of recurrent selective sweeps that each favours a novel resistance or virulence allele that goes to fixation. Host-pathogen coevolution can alternatively lead to a 'trench warfare', i.e., balancing selection, maintaining certain alleles at loci involved in host-pathogen recognition over long time scales. Recently, technological and methodological progress has enabled detection of footprints of selection directly on genes, which can provide useful insights into the processes of coevolution. This knowledge can also have practical applications, for instance development of vaccines or drugs. Here we review the methods for detecting genes under positive selection using divergence data (i.e., the ratio of nonsynonymous to synonymous substitution rates, d(N)/d(S)). We also review methods for detecting selection using polymorphisms, such as methods based on F(ST) measures, frequency spectrum, linkage disequilibrium and haplotype structure. In the second part, we review examples where targets of selection have been identified in pathogens using these tests. Genes under positive selection in pathogens have mostly been sought among viruses, bacteria and protists, because of their paramount importance for human health. Another focus is on fungal pathogens owing to their agronomic importance. We finally discuss promising directions in pathogen studies, such as detecting selection in non-coding regions.