We write a test class to ensure that apex classes and triggers are working as expected, by testing it with single and bulk record processing, for positive test cases and negative test cases.

Test classes are also required when deploying apex classes and triggers in production orgs.