The chemical reactions and pathways resulting in the formation of a thioester, a compound of general formula RC(=O)SR' in which the linking oxygen in an ester is replaced by a sulfur atom. They are the product of esterification between a carboxylic acid and a thiol.