{"title":"Test reports","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-testing-reports/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-testing-reports, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-testing-reports","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"How to validate if a report produces correct data","date":"2021-04-01","meta":{"topic":"article"},"outline":[{"level":2,"title":"Example","slug":"example","at":549,"chars":2135},{"level":2,"title":"Remarks","slug":"remarks","at":2684,"chars":1146},{"level":2,"title":"Related information","slug":"related-information","at":3830,"chars":115}],"text":"Testing your report requires you to run it and to verify the data output. This practice helps you ensure that your customers are presented with complete and accurate data.\nBefore extensions, the output of a report was saved to a file, but extensions deployed to Dynamics 365 Business Central can't access the file system and therefore must save the output of a report to a stream. Codeunit 131007 `Library - Report Dataset` offers a high-level API for running and testing the output of reports that doesn't require direct access to the file system.\n## Example\nThe following example shows how to initialize the codeunit 131007 `Library - Report Dataset` by using the RunReportAndLoad method. This method is preferred as it runs the report and initialize the `Library - Report DataSet` codeunit. To verify the output, call either the AssertElementWithValueExists or the AssertElementWithValueNotExist method. The other methods in the library should work as well if they don't contain \"Tag\" in the name. RunRequestPage and `[RequestPageHandler]` are optional and you can use them when you want to open the request page.\n> TIP\n> If you want to run the report separately and load the data from the input stream manually, you can use the LoadDataFromInstream method.\n```al\ncodeunit 50105 MyReportTesting\n{\n    Subtype = Test;\n\n    [Test]\n    [HandlerFunctions('RemittanceAdviceJournalRequestPageHandler')]\n    procedure TestingReports()\n    var\n        XmlParameters: Text;\n        LibraryReportDataset: Codeunit \"Library - Report Dataset\";\n        GenJournalLine: Record \"Gen. Journal Line\";\n    begin\n        // CreateRemittanceAdvices();\n        // Commit(); // required after data changes and before calling RunRequestPage\n\n        // Run the Report Remittance Advice - Journal.\n        XmlParameters := Report.RunRequestPage(Report::\"Remittance Advice - Journal\");\n        LibraryReportDataset.RunReportAndLoad(Report::\"Remittance Advice - Journal\", GenJournalLine, XmlParameters);\n\n        // Verifying Total Amount on Report.\n        LibraryReportDataset.AssertElementWithValueExists('Amt_GenJournalLine', GenJournalLine.Amount);\n    end;\n\n    [RequestPageHandler]\n    procedure RemittanceAdviceJournalRequestPageHandler(var RemittanceAdviceJournal: TestRequestPage \"Remittance Advice - Journal\")\n    begin\n        // Empty handler used to close the request page. We use default settings.\n    end;\n}\n```\nAny changes done in the handler above results in the XmlParameters being changed and applied automatically when the report runs. Examples of the implementation in the existing tests are in codeunit 133770 `ERM Remittance Report UT` and codeunit 134141 `ERM Bank Reconciliation`.\n## Remarks\nmethods-auto/testrequestpage/testrequestpage-saveasxml-method uses a different format than methods-auto/report/report-saveasxml-method or methods-auto/report/report-saveas-method by serializing the output of Report Previewer. This is a component that will be deprecated in the future and replaced with the new methods that can be used for the new tests. Another difference is that TestRequestPage.SaveAsXML requires files to be saved to disk and loaded, while other methods work in memory, making them more efficient.\n> NOTE\n> The existing tests still need support and the codeunit solves this problem by supporting both formats for now. TestRequestPage.SaveAsXML uses Tags for values, while the new format uses attributes. This means that you cannot use any public method that contains \"Tag\" in the name to test the reports generated in the memory.\n> TIP\n> From the Business Central client, you can export report results as raw data to an XML file. Use the file to help validate that the report returns the expected data. To export a report dataset to XML, run the report and select the Send to > XML (data only) on the request page.\n## Related information\nReports Overview<devenv-reports>\ndevenv-testing-pages\ndevenv-test-codeunits-and-test-methods"}