A bad battery can cause a car to stall when you're driving because when a battery is bad the alternator has to work much harder to put out the required voltage to keep your car running.
A bad alternator can also cause your car to stall if it can't put out enough voltage and your battery has to supply the voltage itself to keep your cars engine running.
You can test for a bad alternator by removing the positive or negative battery cable while the car is running.
If the car dies out after removing the battery cable then your alternator is faulty.