Do you mean shelf life? or do you mean how long it will last in a device, are we talking primary (non rechargeable) or secondary (rechargeable) batteries. If secondary do you mean shelf life, or how many charge discharge cycles. I will answer the question for the shelf life of a primary alkaline battery for now, since it is the most common.
Shelf life is based on the particular chemistry and how long they have lasted in the past via quality tests. A battery company can also age a battery by abusing it in certain ways such as heating and cooling it many times and exposing it to high heat and humidity. By aging a large batch of test batteries they can determine how a particular chemistry will last. Alkaline are typically rated to have a shelf life of about 5 years from the manufacturing date. Although there have been changes to alkaline designs over the years for the most part the chemistry hasn't changed that much so old data still applies.
They leave samples to sit on a shelf and look at them test their voltage under load when they expire the work out a shelf life so you can still use them before they give out. this can some times go wrong I have had experience of faulty batteries in past times. the zinc chloride types are prone to leakage when stored in the wrong way.
__________________
There's them that knows and them that just thinks they know, whitch are you? Stir the pot and see what rises up. I have catalytic properties I get a reaction going.