Yes, it happens all the time.
The way a generic is approved is called a double-blind study. Half of volunteers are given a brand medication and half of them are given the generic. Then the doctors and nurses study the reaction in the body to that. Then later, either that weekend or in the future, the same patients are given alternate drugs. They then, again, determine the reaction of the product. If they're determined to be equivalent, then they can be approved.
As I said, they are also subject to the same good clinical and manufacturing practices. These products are considered as safe and efficacious as their comparable originator products.