Batteries can fail due to inadequate charging, electrolyte chemical imbalances, shorts, age and a host of other things, but there are some general ways to check out major problems.
Ideally, you want to check a battery's individual cells using a hydrometer. Density of the fluid varies as a function of charge, so the hydrometer's readings can be extremely informative. A reading of 1.270 indicates a fully-charged battery, whereas one of 1.175 indicates a low charge.
Contrary to popular belief, most batteries can be opened up to reveal the cells. Do so carefully and don't have any open flames near the cells, since they produce hydrogen gas.
Another check of battery condition can be through the use of a voltmeter. The meter can show the state of charge, of course, typically showing about 12.5 volts or 6.5 volts for those respective systems. If a meter reads less than 9 volts or 5 volts with no loads on the battery, it is probably undercharged.
Next, engage the starter with the meter connected to the battery. If, on 12-volt systems, the meter reads less than 9 volts during this period the battery is undercharged. The same test can be made by turning on the headlights, but the voltage drop won't be as large. In this case a reading below 10.5 volts would be of concern.
During charging, voltmeter readings can quickly show if the alternator or generator is working correctly. Alternator-equipped cars will show voltage readings of 14.5 or slightly higher, while generator-equipped cars will show about one volt less (such cars must have their engines revved to at least 1500 rpm or generators will not begin to charge.)
Individual cells can be read with voltmeters, but doing so exposes the metal tips of the leads to acid. They must be neutralized and cleaned immediately to prevent corrosion.