For many bacterial infections, drug resistant mutants are likely present by the time antibiotic treatment starts. Nevertheless, such infections are often successfully cleared. It is commonly assumed that this is due to the combined action of drug and immune response, the latter facilitating clearance of the resistant population. However, most studies of drug resistance emergence during antibiotic treatment focus almost exclusively on the dynamics of bacteria and the drug and neglect the contribution of immune defenses. Here, we develop and analyze several mathematical models that explicitly include an immune response. We consider different types of immune responses and investigate how each impacts the emergence of resistance. We show that an immune response that retains its strength despite a strong drug-induced decline of bacteria numbers considerably reduces the emergence of resistance, narrows the mutant selection window, and mitigates the effects of non-adherence to treatment. Additionally, we show that compared to an immune response that kills bacteria at a constant rate, one that trades reduced killing at high bacterial load for increased killing at low bacterial load is sometimes preferable. We discuss the predictions and hypotheses derived from this study and how they can be tested experimentally.