Now that we've built our To-Do List application, it's crucial to test it thoroughly. Testing ensures that our code behaves as expected and catches any bugs before our users do. We'll approach this by manually testing each core functionality and considering edge cases.
Our To-Do List application has several key functions we need to verify:
graph TD
A[Start Testing]
B{Add a Task}
C{View Tasks}
D{Mark Task as Complete}
E{Remove a Task}
F{Empty List Scenario}
G{Duplicate Task Scenario}
H[End Testing]
A --> B
A --> C
B --> C
C --> D
C --> E
D --> C
E --> C
C --> F
C --> G
F --> H
G --> H
Let's walk through the testing steps:
- Adding Tasks: Start by adding a few tasks. Check if they appear correctly in the list. Try adding tasks with different lengths and characters to ensure flexibility.
add_task('Buy groceries')
add_task('Schedule dentist appointment')
add_task('Read Python book chapter')
view_tasks()- Viewing Tasks: After adding tasks, use the
view_tasks()function. Ensure all added tasks are displayed with their correct indices and completion status (initially 'incomplete').
- Marking Tasks as Complete: Try marking a few tasks as complete. Use their corresponding indices. Then, call
view_tasks()again to verify that their status has changed to 'complete'.
mark_complete(1)
mark_complete(3)
view_tasks()- Removing Tasks: Remove some tasks using their indices. After removal, call
view_tasks()to confirm they are no longer in the list. Try removing a task that doesn't exist to see how the application handles it.
remove_task(2)
view_tasks()
remove_task(99) # Test invalid index- Edge Cases - Empty List: What happens if you try to view tasks when the list is empty? Or try to mark a task as complete on an empty list? Or remove a task from an empty list? Test these scenarios to ensure graceful handling, perhaps by displaying informative messages.
clear_all_tasks() # Assume a function to clear for testing
view_tasks()
mark_complete(1) # Should handle empty list
remove_task(1) # Should handle empty list- Edge Cases - Duplicate Tasks: While our current implementation doesn't prevent duplicate task entries, consider if you want to prevent them. If so, you'd add a check before adding a task. For now, test adding the same task multiple times and observe the output.
add_task('Buy milk')
add_task('Buy milk')
view_tasks()- Invalid Inputs: Test with invalid inputs for task indices. For example, providing negative numbers, non-integer values, or indices that are out of bounds. Ensure your application provides helpful error messages or handles them gracefully without crashing.
mark_complete(-1)
mark_complete('abc')
remove_task(100)By systematically going through these test cases, you can gain confidence in the stability and correctness of your To-Do List application. Documenting your tests, even for a simple project like this, is a good habit to get into for larger, more complex applications.