There are species that have both testes and ovaries, and they are both male and female. There are some plants that have male and female parts in the same flower, or they have both male and female flowers. Some fish can be males and then as they grow, become females.
The reason behind sexual reproduction is the exchange of mutations. If an individual can obtain the mutations of other individuals and pass it on to its offsprings, then genetic diversity has increased. At the population level, there is a greater degree of genetic variation than in clonal species. The greater genetic diversity is a hedge against any new disease that may crop up. For example, the plague, which devasted Europe in the Middle Ages, did not completely wipe out the population, because some Europeans had genes that made them resistant to the disease. Similarly, chimpanzees had been devasted by AIDS, but there were a few individuals that were resistant to the virus and they survived. Without genetic diversity, a species is more vulnerable to diseases and may become extinct.
If the advantage of sexual reproduction is to exchange genes, then having separate sexes forces these individuals to exchange genes by mating with other individuals. It makes self-fertilization impossible, ensuring that genetic diversity is always maintained. Even though it means reproduction is not possible if only a single individual remains, this strategy of separating the sexes has proven successful overall and it is widespread among sexually reproducing species.