In genetics, complementation refers to a relationship between two different strains of an organism which both have homozygous recessive mutations that produce the same phenotype (for example, a change in wing structure in flies). These strains are true-breeding for their mutation — when crossed with themselves they will always produce offspring with the mutant phenotype. If, when these strains are crossed with each other, some offspring show recovery of the wild-type phenotype, these strains show "genetic complementation". A complementation test (sometimes called a "cis-trans" test) refers to this experiment, developed by American geneticist Edward B. Lewis. It answers the question, if a wild-type copy of gene X rescues the function of the mutant allele that is believed to define gene X. If there is an allele with an observable phenotype whose function can be provided by a wild type genotype (i.e., the allele is recessive) — one can ask whether the function that was lost because of the recessive allele can be provided by another mutant genotype. If not, the two alleles must be defective in the same gene. The beauty of this test is that the trait can serve as a read-out of gene function even without knowledge of what the gene is doing at a molecular level. 
Complementation arises because loss of function in genes responsible for different steps in the same metabolic pathway can give rise to the same phenotype. When strains are bred together, offspring inherit wildtype versions of each gene from either parent. Because the mutations are recessive, there is a recovery of function in that pathway, so offspring recover the wild-type phenotype. Thus, the test is used to decide if two independently derived recessive mutant phenotypes are caused by mutations in the same gene or in two different genes. If both parent strains have mutations in the same gene, no normal versions of the gene is inherited by offspring; they express the same mutant phenotype and complementation has failed to occur.
In other words:
- If the combination of two haploid genomes containing different recessive mutations yields a mutant phenotype, then the mutations must be in the same gene.
- If the combination of two haploid genomes containing different recessive mutations yields the wild type phenotype, then the mutations must be in different genes.
There are exceptions to these rules. Two non-allelic mutants may occasionally fail to complement (called "non-allelic non-complementation" or "unlinked non-complementation"). This situation is rare and is dependent on the particular nature of the mutants being tested. For example, two mutations may be synthetically dominant negative. Another exception is transvection, in which the heterozygous combination of two alleles with mutations in different parts of the gene complement each other to rescue a wild type phenotype.