This test suite validates the reply-related features in a JavaFX-based Q&A application backed by a relational database. The ReplyTest.java file uses JUnit 5 to ensure that creating, reading, updating, and deleting replies associated with answers functions as expected.
The tests are implemented using the JUnit 5 framework and interact with the database via the DatabaseHelper class. Additional domain classes used include Question and Answer.
Each test prints clear and descriptive output to the console to help trace the test logic and verify that data is being correctly handled.
Each test method follows this structure:
- Setup (@BeforeEach): Connects to the database, adds a test question and a base answer.
- Test Execution: Runs a specific CRUD operation involving replies.
- Teardown (@AfterEach): Deletes all answers for the test question, deletes the test question itself, and closes the database connection.
| Method | Purpose |
|---|---|
testAddReply_Positive |
Adds a valid reply and verifies it was inserted correctly. |
testAddReply_Negative_EmptyReply |
Attempts to add an empty reply, expecting a SQLException. |
| Method | Purpose |
|---|---|
testGetReplies_Positive_MultipleReplies |
Adds two replies and confirms both are retrieved. |
testGetReplies_Negative_NoReplies |
Ensures that no replies are returned if none were added. |
| Method | Purpose |
|---|---|
testUpdateReply_Positive |
Updates an existing reply and verifies the new content. |
testUpdateReply_Negative_EmptyContent |
Updates a reply to an empty string. Assumes the database allows this and verifies the result. |
| Method | Purpose |
|---|---|
testDeleteReply_Positive |
Adds and then deletes a reply. Verifies it no longer exists. |
testDeleteReply_Negative_NonExistent |
Attempts to delete a reply that does not exist. Expects no crash or exception, and verifies the state remains unchanged. |
To execute the tests, use your preferred Java IDE (such as IntelliJ IDEA or Eclipse) or run via command line with a build tool like Maven or Gradle that includes JUnit 5 support.
Make sure your database is properly configured and accessible via the DatabaseHelper class before running the tests.
Zoom Recording Link: SCREENCAST
Passcode: Q@7EBUmz
This is the HTML: Doc