How to Implement Class Tests?
Implementation of Class Tests
Overview of Class Testing
- The discussion focuses on implementing class tests, which exercise a system through its classes by creating objects and invoking their methods.
- These tests can be used in both unit testing (without external dependencies) and integration testing (with real service versions).
Characteristics of Class Tests
- Class tests do not directly relate to scenarios or requirements specified by stakeholders; instead, they focus on properties deemed important by developers.
- An example test checks if the student registration is initially empty, verifying that there are no students registered.
Test Implementation Details
- The test verifies the initial state of the student registry using a method to get the list of registered students and checking its size.
- A
beforeEachclause sets up behavior before each test runs, ensuring a new instance of the student registry is created for consistency.
Reusability in Testing
- The setup process avoids redundancy by initializing common variables in the
beforeEachclause rather than repeating it in every individual test case.
- Another test checks if duplicate entries (students with the same CPF number) are prevented from being added to the registry.
Detailed Example: Duplicate Student Registration
- This specific test includes three parts: setup (creating objects), action (attempting to add a second student), and verification (checking expected outcomes).
Understanding Class Testing in Student Registration Systems
Key Concepts of Class Testing
- The discussion revolves around the properties of a student registration class, emphasizing that an object representing a student will only exist after certain actions are performed.
- It is highlighted that these tests focus on verifying specific attributes and functionalities of the class, which are crucial for ensuring proper system behavior.
- The creation of objects and method invocation is central to this testing process, indicating a hands-on approach to validating class functionality.
- There is no direct guidance from stakeholder requirements; instead, developers seek to confirm details about method specifications and expected behaviors through these tests.