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

Test isolation

With a test runner enabling us to control the execution of all tests in one run, we also need to have control of the data created in one test codeunit, so that it will not influence the results of the tests in the next test codeunit. For this, the test codeunit TestIsolation property has been introduced, and it has three possible values:

  • Disabled: When selecting this value, or not setting the TestIsolation property explicitly, as this is the default value, any database transaction will be effectuated; after the execution of tests triggered by the test runner, the database will have changed compared to before running the test runner
  • Codeunit: When selecting this value, after a test codeunit execution has completed fully, all data changes made to the database will be reverted/rolled back
  • Function: When selecting this value, when a single test function has completed, all data changes made to the database will be reverted/rolled back

Related to this, it makes sense to share a couple of thoughts on running tests and their isolation:

  1. Test isolation applies to database transactions, but does not apply to changes made outside of the database, and to variables, including temporary tables
  2. With test isolation, Codeunit, or Functionall data changes will be rolled back, even if they were explicitly committed using the AL Commit statement
  3. Running test codeunits outside of the test isolation, either Codeunit or Function of a test runner will effectuate any database transaction
  4. Using test isolation, Function will give extra overhead compared to Codeunit, resulting in longer execution time, as with the ending of each test function, the database changes have to be reverted
  1. Setting the test isolation to Function might be unwanted, as it fully disables dependencies between test functions, which might be needed when, for an extended test scenario, intermediate results should be reported, and this has been achieved by a series of individual, but interdependent, test functions
  2. With the TestIsolation property of a test runner, we have control over how to revert data changes in a generic way; as we will later see, the test function TransactionModel tag allows us to have control of the transaction behavior of individual test functions
主站蜘蛛池模板: 永和县| 株洲市| 鸡东县| 营口市| 高雄县| 通江县| 北宁市| 海丰县| 文登市| 日土县| 溧水县| 荔浦县| 西盟| 南汇区| 确山县| 荃湾区| 高雄市| 卓尼县| 长寿区| 永靖县| 尼勒克县| 金山区| 无锡市| 长泰县| 华容县| 栖霞市| 海伦市| 镇康县| 醴陵市| 五峰| 永安市| 乃东县| 合山市| 宿州市| 黄大仙区| 仁寿县| 马公市| 讷河市| 微山县| 酒泉市| 抚顺市|