如何在实际项目中的Microsoft Dynamics AX 2012中进行单元测试 [英] How to do unit testing in Microsoft Dynamics AX 2012 in a real world project

查看:79
本文介绍了如何在实际项目中的Microsoft Dynamics AX 2012中进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dynamics AX 2012带有单元测试支持.

Dynamics AX 2012 comes with unit testing support.

要进行有意义的测试,需要提供一些测试数据(存储在数据库的表中).

To have meaningful tests some test data needs to be provided (stored in tables in the database).

要获得可重复的单元测试结果,我们需要在每次运行测试时在表中存储相同的数据. 现在的问题是,我们如何才能做到这一点?

To get a reproducable outcome of the unit tests we need to have the same data stored in the tables every time the tests are run. Now the question is, how can we accomplish this?

我了解到可以将TestSuite的隔离级别设置为SysTestSuiteCompanyIsolateClass.在运行测试之后,这将创建一个空公司并删除该公司.在setup()方法中,我可以使用insert语句将测试数据填充到表中. 这在小情况下可以很好地工作,但是如果您有一个真实的项目,则变得非常麻烦.

I learned that there is the possibility of setting the isolation level for the TestSuite to SysTestSuiteCompanyIsolateClass. This will create an empty company and delete the company after the tests have been run. In the setup() method I can fill my testdata into the tables with insert statements. This works fine for small scenarios but becomes cumbersome very fast if you have a real life project.

我想知道是否有人在实际场景中提供了有关如何使用X ++单元测试框架的实用解决方案.非常感谢任何输入.

I was wondering if there is anyone out there with a practical solution of how to use the X++ Unit Test Framework in a real world scenario. Any input is very much appreciated.

推荐答案

我同意在一个新的空公司中创建测试数据仅适用于相当琐碎的场景或您自己实现整个数据结构的场景.但是,只要需要现有的数据结构,这种方法就会变得非常耗时.

I agree that creating test data in a new and empty company only works for fairly trivial scenarios or scenarios where you implemented the whole data structure yourself. But as soon as existing data structures are needed, this approach can become very time consuming.

过去对我有效的一种方法是在现有公司中进行单元测试,该公司已经具有运行测试所需的大多数配置数据(例如财务设置,库存设置等).测试本身在ttsBegin-ttsAbort块中运行,因此单元测试实际上不会创建任何数据.

One approach that worked well for me in the past is to run unit tests in a existing company that already has most of the configuration data (e.g. financial setup, inventory setup, ...) needed to run the test. The test itself runs in a ttsBegin - ttsAbort block so that the unit test does not actually create any data.

另一种方法是实现与测试无关的数据提供者方法,但是创建经常在单元测试中使用的数据(例如,创建产品的方法).创建一组有用的数据提供程序方法需要花费一些时间,但是一旦它们存在,编写单元测试的速度就会大大提高.请参见 SysTest第V部分:测试执行(结果,运行程序和侦听器),有关微软如何使用类似方法(或者至少他们曾经在2007年使用AX 4.0).

Another approach is to implement data provider methods that are test agnostic, but create data that is often used in unit tests (e.g. a method that creates a product). It takes some time to create a useful set of data provider methods, but once they exist, writing unit tests becomes a lot faster. See SysTest part V.: Test execution (results, runners and listeners) on how Microsoft uses a similar approach (or at least they used to back in 2007 for AX 4.0).

这两种方法也可以组合使用,您可以在ttsBegin-ttsAbort块中调用数据提供者方法,以仅为单元测试创​​建所需的数据.

Both approaches can also be combined, you would call the data provider methods inside the ttsBegin - ttsAbort block to create the needed data only for the unit test.

另一种有用的方法是使用doInsertdoUpdate创建测试数据,特别是如果您仅对几个字段感兴趣并且不需要创建完全有效的记录时.

Another useful method is to use doInsert or doUpdate to create your test data, especially if you are only interested in a few fields and do not need to create a completely valid record.

这篇关于如何在实际项目中的Microsoft Dynamics AX 2012中进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆