Add tests for Services, List Modules, Chart Modules, Autocomplete (#5349)#5350
Add tests for Services, List Modules, Chart Modules, Autocomplete (#5349)#5350boris-unckel wants to merge 1 commit intofisharebest:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5350 +/- ##
============================================
+ Coverage 35.37% 36.81% +1.44%
Complexity 11196 11196
============================================
Files 1166 1166
Lines 48031 48031
============================================
+ Hits 16990 17684 +694
+ Misses 31041 30347 -694 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi Boris, I am assuming that this PR was created by an AI coding assistant... With unit tests, it is best practice for each unit test to test only one class. This is often refered to as the "SUT" - "System under test". So, when testing the request handlers, we only need to test the request handles. Dependencies (such as In fact, the design of the code ("Services" as constructor dependencies to the request handlers) was designed to allow exactly this type of separation. So, could you perhaps ask your AI tool to rewrite the unit tests for the request handlers with this in mind. The "test double" approach makes it trivially easy to provide different values to the request handler (e.g. no data, etc.) to allow every code path and edge-case value to be covered by the test. |
|
Dear Greg, Thank you very much for reviewing the tests; this is valuable feedback for me. Yes, this is code from Claude CLI. It was created as a byproduct because I needed a test environment for webtrees. I act as a web administrator for a relative who is involved in genealogy. We’ve both become big fans of the software, each from our own perspectives. I’ll adapt the unit test suite (from which the upstream contribution originated) based on your specific feedback. I still need a little time for the other test suites, but then I’ll publish those as open source as well and, of course, offer them to the upstream project here. My goal is to give developers who implement extensions a way to test them regressively against any stable or latest unstable builds as easily as possible. Webtrees is a great project, and I have great respect for what has already been achieved. Best regards, |
Summary
This PR fills 23 previously empty test stubs (from commit a813962 "Add minimal test scripts for every class") with 137 new test methods covering core services, list modules, chart modules, and autocomplete request handlers.
All tests use the existing
TestCaseinfrastructure with SQLite in-memory database anddemo.gedfixture. No changes to production code.Scope
Services (67 tests)
GedcomImportServiceTestSearchServiceTestGedcomExportServiceTestGedcomServiceTestTreeServiceTestRelationshipServiceTestRomanNumeralsServiceTestList Modules (14 tests)
IndividualListModuleTestFamilyListModuleTestSourceListModuleTestRepositoryListModuleTestNoteListModuleTestMediaListModuleTestSubmitterListModuleTestChart Modules (10 tests)
AncestorsChartModuleTestCompactTreeChartModuleTestPedigreeChartModuleTestDescendancyChartModuleTestFanChartModuleTestHourglassChartModuleTestAutoComplete Handlers (5 tests)
AutoCompletePlaceTestAutoCompleteSurnameTestAutoCompleteCitationTestKnown issue found during testing
AutoCompleteCitationTest::testHandleReturnsJsonForValidSourceis marked as skipped. During test development,FamilyFactory::mapper()was observed returningnullfor families whose members are privacy-restricted, causing a fatal error in the citation autocomplete handler.This appears to be a pre-existing issue, not introduced by these tests. I can file a separate issue if helpful.
Test data
All tests use the bundled
demo.gedfixture via$this->importTree('demo.ged'). No additional test data files are needed.How to run