Menu
Coddy logo textTech

Testing and Integration

Part of the Object Oriented Programming section of Coddy's Dart journey — lesson 106 of 110.

challenge icon

Challenge

Easy

In the previous lesson, you built an admin interface for managing library inventory. Now it's time to bring everything together by creating a comprehensive test suite that validates all the components of your Library Management System work correctly together.

You'll add a LibraryTester class that runs integration tests across all your library features - verifying that books, users, admins, borrowing, searching, and inventory management all function as expected when used together.

  • book.dart, user.dart, admin.dart, library.dart: Keep your existing classes unchanged.
  • library_tester.dart: Create a new LibraryTester class that validates your library system. It should have a Library instance and include these test methods:
    • setupTestData() - registers an admin (A001, Test Admin), adds two books via the admin (978-0-01, Book One, Author A and 978-0-02, Book Two, Author B), and registers a user (U001, Test User)
    • testBorrowing() - borrows the first book for the user, attempts to borrow it again (should fail), then returns it. Print Borrowing test: PASS after completion.
    • testSearch() - searches for books with Book in the title, prints Search found: X books where X is the count, then prints Search test: PASS
    • testAdminOperations() - removes the second book using the admin, prints the book count as Books after removal: X, then prints Admin test: PASS
    • runAllTests() - calls setupTestData(), then runs all three test methods in order, and finally prints All tests completed!
  • main.dart: Create a LibraryTester instance and call runAllTests() to execute the full test suite.

Expected output:

A001 added "Book One"
A001 added "Book Two"
U001 borrowed "Book One"
Book not available
U001 returned "Book One"
Borrowing test: PASS
Search found: 2 books
Search test: PASS
A001 removed "Book Two"
Books after removal: 1
Admin test: PASS
All tests completed!

Try it yourself

import 'library_tester.dart';

void main() {
  // TODO: Create a LibraryTester instance and call runAllTests()
}

All lessons in Object Oriented Programming