web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Unit Testing

(0) ShareShare
ReportReport
Posted on by

Hi,

I would like to implement unit testing in my all new development. I was googling found few article in MSDN which talks about unit testing for employee class and Stack operation. Also found a calculator example.

I am looking for real class in AX which talks to table and few operations etc. If anyone has such experience please give me more details.

It would be nice if some can provide a sample code.

Thanks in advance               

Umeshnath

 

 

*This post is locked for comments

I have the same question (0)
  • Somanna G.L Profile Picture
    on at
  • Fav Mohammed Profile Picture
    on at

    Hello Umeshnath,

    As you mentioned above, there are a few articles on MSDN which talk about Unit Testing. Some examples do include the Employee class, however there is also more information regarding various Test classes and information on how to create them, derive results and organise them all on the below link:

    msdn.microsoft.com/.../aa874515.aspx

    There are also some blog articles which discuss SysTest. There are a few blogs written by the below author which contain information on Unit Tests:

    blogs.msdn.com/.../dave_froslie

    One such example is "Are all SysTest tests Unit tests?", a blog containing a significant amount on information on creating SysTest's with Best Practices. Unfortunately i cannot give you any hands on detailed experience of Unit Testing, however i hope the above will give you some further insight into Unit Testing.

    Hope this Helps!
    Regards
    Fav

  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    I would recommend the following steps:

    1. Write the testable code. Often you can isolate all business logic in such a way that you are not much interested in database queries or you can mock them (dependency injection is your friend :)). You quickly realize that you have to write code differently than what you can normally see in AX - and that's right, the "normal" AX code is virtually untestable.
    2. Use test case isolation, e.g. SysTestSuiteCompanyIsolateClass (find a brief description here). It allows you to write data to DB, read them etc. and not to worry about cleanup.
    3. Sometimes you really need pre-prepared data, because trying to set them up for a test would be too difficult (due to high complexity in database, e.g. to save a record you have to set values to 10 other tables, due to mandatory foreign key references). I would recommend to create a separate company with test data (these are not to be changed by unit tests, but you have to maintain them as your application changes).


    I use just the first two points - the third one requires cooperation of the whole team. And I don't try to write unit tests for everything - I rather try to isolate all complex logic to testable classes and leave other parts to be tested by other means.

  • Community Member Profile Picture
    on at

    Hi, thanks for posting,

    I was using SysTestSuiteCompanyIsolateClass for database related testing .However the issue is, if had a number sequence how would I create the sequence, my test case create new company and could not find the sequence , setting up these kind task each unit test case is night mare.

  • Suggested answer
    PA-22040759-0 Profile Picture
    6,194 on at

    Here's a good blog series, written ny one of the guys who originally write the unit test framework in AX. It's written for 4.0, but still valid: blogs.msdn.com/.../systest-part1-assertions.aspx

  • Community Member Profile Picture
    on at

    Thanks for the post, but it doesn't talk about actual data base operations

  • Martin Dráb Profile Picture
    237,967 Most Valuable Professional on at

    Let me repeat the options:
    1) You can try to redesign your solution not to depend on such things in database.
    2) You can prepare test data on the fly
    And if you can't use any of these:
    3) Prepare your data in AX as usual and let your tests use them. It significantly simplifies your tests, on the other hand you have to maintain the data together with your tests. (Your tests still shouldn't make permanent changes to such data - use TTS isolation, tearDown etc. to clean the data up.)

  • Community Member Profile Picture
    on at

    Hi,

    Thanks for the posting.

    For preparing test data is there any built in mechanism or we have to do it manually. For example the project I am working is invoice automation, in order  to set up like vendor, customer, sales order, Purchase order, Number sequence   etc is a night mare. I know it is worth spending ,eventually I will have all the set up data but the current time frame is not allowing me to do. I wish any built in mechanism does this.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans