Many factors affect the cost associated with treating heartworm infection, including diagnostic testing, hospitalization, medication, and office visits. Preventing heartworm is much less expensive, which is why most veterinarians recommend that you keep your pet on heartworm prevention year-round.