Quality cost in testing is calculated by considering various components: prevention costs (expenses on activities to prevent defects), appraisal costs (costs associated with evaluating and verifying product quality), internal failure costs (expenses caused by defects detected before release), and external failure costs (costs resulting from defects discovered post-release, such as customer support and reputation damage). Summing up these categories gives us the total cost of quality in testing.