官术网_书友最值得收藏!

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
For a short and clear description of the four-phase design pattern, please refer to the following link:
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();
主站蜘蛛池模板: 鱼台县| 达州市| 阳春市| 晋宁县| 玛曲县| 蒲江县| 东源县| 铜山县| 静乐县| 东城区| 秦皇岛市| 宣城市| 四子王旗| 二手房| 彝良县| 凤翔县| 尼木县| 镇康县| 长垣县| 上杭县| 西青区| 志丹县| 调兵山市| 嘉义市| 朝阳县| 内黄县| 乌鲁木齐市| 桑日县| 宜黄县| 正宁县| 印江| 阿勒泰市| 抚松县| 铜陵市| 玛曲县| 历史| 阿鲁科尔沁旗| 德令哈市| 邯郸县| 辽阳县| 宁海县|