Skip to main content

Notifications

Announcements

No record found.

Supply Chain Management forum
Suggested answer

When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?

Posted on by
Hi all,
 
In FNO, we have a logic to modify the session date, in order to operate on backdate.
 
Now, I want to create some test data in a past period in unit tests.
 
For example, table InventDim has a system field CreatedDateTime. I need to create bundle of InventDim records with CreatedDateTime = one year ago.
 
How can I achieve this?
 
I tried with DateTimeUtil::setSystemDateTimeWithCascadeOption(transDateTime, true), but it is not helpful.
 
Thanks.
  • Martin Dráb Profile Picture
    Martin Dráb 228,166 Most Valuable Professional on at
    When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?
    That's irrelevant. You see classes in AOT even if they internal, and you see classes for unit testing (e.g. SysTestRunner) there as well. Therefore this is not an answer.
     
    I guess they're either not included in the standard application (it's internal development of your company and useless as a suggestion here, or they actually aren't X++ classes. Maybe they're .NET classes and you forgot to mentioned their namespace (at least). It would have been clear if you actually answered my previous question.
     
    Please clarify that, otherwise your answer is not useful. If you have no idea, allow us to help you by providing more information, such as mentioning when you see these classes used.
  • Kai Cheng Profile Picture
    Kai Cheng on at
    When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?
    Hi, Martin,
    I think these codes are for internal usage only. They are used for unit tests of functionality.
  • Martin Dráb Profile Picture
    Martin Dráb 228,166 Most Valuable Professional on at
    When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?
    Kai, My application (10.0.37) doesn't contain these classes (AtlDateTimeHelper and InventTransferOrderCreateFromSalesLineTest).
    What is your version and which model(s) contains these classes?
  • Suggested answer
    Kai Cheng Profile Picture
    Kai Cheng on at
    When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?
    Found a class AtlDateTimeHelper, not sure whether this can apply to my scenario.
     
    Refer to InventTransferOrderCreateFromSalesLineTest.xml

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,326 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,166 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans