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

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();
主站蜘蛛池模板: 巴林左旗| 德阳市| 阳高县| 黑龙江省| 都昌县| 祁连县| 石城县| 新邵县| 九江县| 邛崃市| 无为县| 万州区| 沁源县| 连平县| 彰化市| 大连市| 勃利县| 新宁县| 楚雄市| 陆川县| 鞍山市| 巩义市| 通州市| 晋中市| 翁源县| 东乡县| 宕昌县| 和平县| 南宁市| 阜康市| 镶黄旗| 淮南市| 北票市| 福清市| 旬阳县| 龙里县| 霍林郭勒市| 汉寿县| 革吉县| 陈巴尔虎旗| 饶平县|