- Automated Testing in Microsoft Dynamics 365 Business Central
- Luc van Vugt
- 241字
- 2021-06-24 14:56:54
Understanding test case design patterns
Goal: Learn the basic patterns for designing tests.
If you have been testing software, you might know that each test has a similar overall structure. Before you can perform the action under test, for example, the posting of a document, first, the data needs to be set up. Then, the action will be exercised. And finally, the result of the action has to be verified. In some cases, a fourth phase applies, a so-called teardown, which is used to revert the system under test to its previous state.
The four phases of a test case design pattern are listed as follows:
- Set up
- Exercise
- Verify
- Teardown
http://robots.thoughtbot.com/four-phase-test
This design pattern was typically the pattern used by Microsoft in the early years of C/SIDE test coding. Like the following test function example, taken from codeunit 137295 - SCM Inventory Misc. III, you will encounter it in a vast number of older test codeunits:
[Test] PstdSalesInvStatisticsWithSalesPrice()
// Verify Amount on Posted Sales Invoice Statistics
// after posting Sales Order.
// Setup: Create Sales Order, define Sales Price on Customer
Initialize();
CreateSalesOrderWithSalesPriceOnCustomer(SalesLine, WorkDate());
LibraryVariableStorage.Enqueue(SalesLine."Line Amount");
// Enqueue for SalesInvoiceStatisticsPageHandler.
// Exercise: Post Sales Order.
DocumentNo := PostSalesDocument(SalesLine, true);
// TRUE for Invoice.
// Verify: Verify Amount on Posted Sales Invoice Statistics.
// Verification done in SalesInvoiceStatisticsPageHandler
PostedSalesInvoice.OpenView;
PostedSalesInvoice.Filter.SetFilter("No.", DocumentNo);
PostedSalesInvoice.Statistics.Invoke();