A t-test is a statistical hypothesis test. People use it when they want to compare a property from one group A to some theoretical value. People also use it when they want to compare the property of two groups A and B. They want to decide if the property in group A is different to the theoretical value or to the property in group B.
For example, pretend there are two groups of people. One group exercises a lot and the other doesn't. Do the people who exercise tend to live longer than those who don't? Then the property of interest is the average life time. Is the average life time of people who exercise different to the average life time of people who don't? A t-test can help answer this question.
The t-test is used when the property's variance in the groups is unknown. When people want to do the t-test they have to calculate the variance from the sample (the collection of data). This calculated variance is almost always different to the true variance in the group. The t-test was created to care about this difference.