Z-test and T-test are two statistical hypothesis tests out of many other statistical methods that are used to test hypotheses. One of the major differences between the Z-test and T-test is that the former uses a normal distribution, whereas the latter uses a Student's T-distribution.
Z-test is used mostly to compare population and sample and to find out if there is any difference between them. At times, the standard deviation can be used together with Z-tests provided if it is known. T-test seems to be a better statistical method for small samples, i.e., samples less than 30 (n < 30).
In contrast, Z-test is used mostly when the samples to be handled are more than 30, i.e. (n > 30). However, this does not mean that the T-test cannot be used for large samples, just that it is the most suitable statistical method for small samples. In fact, the use of a T-test for large samples makes it look like you are using Z-test.