Skip to main content

Test Unit Framework

The DotHRB Test Unit framework is a built-in utility designed to ensure the reliability and stability of your application. By automating the verification of your code's behavior, you can catch regressions early and maintain a high standard of quality as your project scales.


Why Unit Testing Matters​

In a dynamic development environment, even small changes can have unintended side effects. Implementing a testing strategy offers several key advantages:

  • Regressions Detection: Quickly identify if new features or bug fixes have broken existing functionality.
  • Documentation by Example: Tests serve as a living technical specification, demonstrating exactly how specific functions and APIs are expected to behave.
  • Faster Refactoring: Confidently restructure or optimize your code knowing that the test suite will immediately alert you to any breaking changes.
  • Improved API Reliability: By testing status codes, headers, and response bodies, you ensure your endpoints remain consistent for end-users and integrations.

Running Tests​

To execute your test suite, use the dothrb test command from your terminal. The framework will scan your project for test definitions, execute them sequentially, and provide a detailed summary of the results.

Understanding the Output​

The test runner provides real-time feedback on each assertion. Each line in the output indicates the timestamp, the result status, the test name, and the specific assertion being evaluated.

2026-06-02 11:44:07 -- myapp start --
2026-06-02 11:44:07.495 OK ✅ firsttest:test_index_page_200(30) Actual 200 Expected 200
2026-06-02 11:44:07.496 OK ✅ firsttest:test_index_api_200(40) Actual 200 Expected 200
2026-06-02 11:44:07.496 FAIL ❌ firsttest:test_index_api_200(41) Actual application/json; charset=utf-8 Expected application/json

2026-06-02 11:44:07.618 Total 3, ❌ failed 1, ✅ passed 2, errors 0

2026-06-02 11:44:07 -- myapp end --
  • PASSED ✅: The logic performed exactly as expected.
  • FAILED ❌: The actual result deviated from the expected outcome. This provides the line number and the specific condition that failed, allowing for rapid debugging.
  • Summary Line: A high-level overview of your total test count, including successes, failures, and any execution errors.

Best Practices​

  1. Isolate Tests: Ensure each test unit focuses on a single responsibility or endpoint to make failures easier to diagnose.
  2. Test Edge Cases: Don't just test the "happy path." Include tests for empty responses, invalid inputs, and unauthorized access.
  3. CI/CD Integration: Integrate dothrb test into your continuous integration pipeline to prevent broken code from reaching production.