Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Business Central forum

Testing procedure

(0) ShareShare
ReportReport
Posted on by 35

Hi,

I have a situation with test extension which I am building.

Let say I have a two companies in Business Central. I want to perform test a procedure which will include both companies. On first company I will generate some Sales Orders and I will generate Purch. Orders and I will send them to another company to process until the end.

I know that CHANGECOMPANY method exists for records but this does not help. 

How can I in AL code declare or call some method to change company and then on some step i call a method which will change company to another, again.

Anyone did something similar? I heard about sessioninfo variable but honestly I didn't find anything useful for my case. Please help if someone have any idea.

Thanks in advance guys!

Categories:
  • GregorSoln Profile Picture
    35 on at
    RE: Testing procedure

    Yes¸, test per company will be the only option.

    Thank you Hannes for your thoughts! I appreciate it!

  • Hannes Holst Profile Picture
    5,767 on at
    RE: Testing procedure

    Hi,

    Yes. Maybe think per company only.

    That means, your test creates data in your current company only.

    When testing the functions in the other company, you create data accordingly to feed the test functions.

  • Suggested answer
    GregorSoln Profile Picture
    35 on at
    RE: Testing procedure

    Hi Hannes, thank you for your reply. 

    I tired to work with sessions but when I start a session in test function i get error:

    "Sessions cannot be started in tests that are run by a TestRunner that has TestIsolation set to Test or Codeunit."

    The solution I see in my case is to refactor the test scenario to smaller pieces to avoid sessions. Changing the Test Isolation doesn't make sense. 

  • Hannes Holst Profile Picture
    5,767 on at
    RE: Testing procedure

    hi,

    CHANGECOMPANY does change the company of the current record-variable only.

    E.g. when you use SalesHeader.CHANGECOMPANY('whatever company it is') all other tables (e.g. Customers) would remain in the original company.

     

    To really work completely in a company, you have to start a new session using StartSession: https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/session/session-startsession-method

     

    You must set a codeunit as parameter which will be executed in the new company.
    E.g. STARTSESSION(SessionId, CODEUNIT::"Create Sales Order", 'whatever company it is', OptionalRecord);

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard > Business Central forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans