Shivd131 commented on PR #5353:
URL: https://github.com/apache/fineract/pull/5353#issuecomment-3806803307

   Hi @adamsaghy ,
   
   I considered a few approaches. I initially thought about writing individual 
test cases for every single report, but I felt that approach would be brittle, 
time-consuming to maintain, and quite resource-intensive. But I feel this would 
be a better way to test it, keeping things quite simple: 
   
   Spin up a real Client/Loan/Office context and inject those IDs into every 
report call. This allows standard reports (like Loan Schedule or Client 
Listings) to actually resolve data and return 200s.
   
   Crucially, I removed the blind try-catch. The test now strictly asserts that 
no report throws a 500:
   
   - 200 OK: Success.
   
   - 400 Bad Request: Logged as expected (since we can't guess custom params 
for every obscure report, but this confirms the validation engine is working).
   
   - 500 Server Error: Fails the build.
   
   ```code
   // Iterate and Execute
           for (GetReportsResponse report : allReports) {
               String reportName = report.getReportName();
   
               Response<RunReportsResponse> response = 
fineractClient().reportsRun.runReportGetData(reportName, commonParams, 
false).execute();
   
               // Strict Validation
               // Allow 200 (Success) OR 400 (Bad Request - Validation Error).
               // FAIL on 500 (Server Error) or any other code.
               if (response.code() == 200) {
                   successCount++;
               } else if (response.code() == 400) {
                   // If it fails, ensure it's a controlled validation error, 
not a crash.
                   validationErrorCount++;
                   log.info("Report '{}' returned 400 (Expected for missing 
specialized params).", reportName);
               } else {
                   // Fail the test if we get a 500 or 404
                   assertThat(response.code()).as("Report '%s' failed with 
unexpected status code", reportName).isNotEqualTo(500);
               }
           }
   ```
   
   I believe this is a sweet spot, it dynamically verifies the execution 
pipeline for the entire report registry and proves stability, without flaking 
out on validation errors or creating an overly complex test suite.
   
   Let me know your take on this, will be open to adjust and work on them.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to