This in turn likely comes from the Latin word "testa", meaning "head" or "skull".
The connection between "head" and "testy" is that a stubborn or irritable person is often seen as being "hard-headed" or inflexible, like a skull.
Over time, the meaning of "testy" shifted to include the current sense of being easily irritated or irritable.