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

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Suggested answer

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

(0) ShareShare
ReportReport
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.
I have the same question (0)
  • Suggested answer
    Kai Cheng Profile Picture
    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
  • Martin Dráb Profile Picture
    236,955 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?
  • Kai Cheng Profile Picture
    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
    236,955 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.

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 244

#2
Siv Sagar Profile Picture

Siv Sagar 222 Super User 2025 Season 2

#3
Danny Bilodeau Profile Picture

Danny Bilodeau 205 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans