The WHO's early-release guideline for antiretroviral treatment (ART) of HIV infection based on a recent trial conducted in 34 countries recommends starting treatment immediately upon an HIV diagnosis. Therefore, the test-and-treat strategy may become more widely used in an effort to scale up HIV treatment and curb further transmission. Here we examine behavioural determinants of HIV transmission and how heterogeneity in sexual behaviour influences the outcomes of this strategy. Using a deterministic model, we perform a systematic investigation into the effects of various mixing patterns in a population of men who have sex with men (MSM), stratified by partner change rates, on the elimination threshold and endemic HIV prevalence. We find that both the level of overdispersion in the distribution of the number of sexual partners and mixing between population subgroups have a large influence on endemic prevalence before introduction of ART and on possible long term effectiveness of ART. Increasing heterogeneity in risk behavior may lead to lower endemic prevalence levels, but requires higher coverage levels of ART for elimination. Elimination is only feasible for populations with a rather low degree of assortativeness of mixing and requires treatment coverage of almost 80% if rates of testing and treatment uptake by all population subgroups are equal. In this case, for fully assortative mixing and 80% coverage endemic prevalence is reduced by 57%. In the presence of heterogeneity in ART uptake, elimination is easier to achieve when the subpopulation with highest risk behavior is tested and treated more often than the rest of the population, and vice versa when it is less. The developed framework can be used to extract information on behavioral heterogeneity from existing data which is otherwise hard to determine from population surveys.