I agree that creating test data in a new and empty company only works for fairly trivial scenarios or scenarios in which you yourself have implemented the entire data structure. But once existing data structures are needed, this approach can become very time consuming.
One approach that worked well for me in the past is to run unit tests in an existing company that already has most of the configuration data (e.g. financial setup, inventory setup, etc.) needed to run the test. The test itself is executed in the ttsBegin - ttsAbort , so the unit test does not actually create any data.
Another approach is to implement data provider methods that are non-specific for testing, but generate data that is often used in unit tests (for example, the method that creates the product). It will take some time to create a useful set of data transfer methods, but once they exist, unit test records become much faster. See SysTest V Part: Running a test (results, runners, and listeners) for how Microsoft uses this approach (or at least they used to return to 2007 for AX 4.0).
Both approaches can also be combined, you must call the data provider methods inside the ttsBegin - ttsAbort block to create the necessary data for the unit test only.
Another useful method is to use doInsert or doUpdate to create test data, especially if you are only interested in a few fields and do not need to create a fully reliable record.
source share