Skip to main content

Notifications

Microsoft Dynamics AX forum
Under review by Community Managers

Under review

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

unit test: what is interactive session, and how to confirm that the test case is running on interactive session or batch?

Posted on by

Description:

 i don't understand what is interactive session, i cannot find any documents about it.

and i have a test class, and there is a test case in it. the test case will open a form though formAdaptor , and i need to judgment whether it running on interactive session. 

i know that we can use isRunningBatch() and hasGUI() to check it. but i don't understand why it is running on batch or why it is running on interactive session? how are these judged?

the following code you can have a reference, i am a little confused what is the basis of judgmet?

if you know, please give me some suggestions, thanks!

For example:

using System;
using System.Globalization;
class TestClass extends SysTestCase
{

    [SysTestMethod]
    public void tsetMethod1()
    {
        boolean beforeBatch = isRunningOnBatch();
        boolean beforeinterative = hasGUI();

        container beforeResult = [beforeBatch, beforeinterative];

        // Arrange
        using (var formAdaptor = BatchJobHistoryFormAdaptor::open())
        {
            // simulate running in interactive session
            
            boolean isBatch = isRunningOnBatch();
            boolean isinterative = hasGUI();
            container result = [isBatch, isinterative];

            // Assert
            this.assertEquals([false /*isbatch*/, true /*isInteractive*/], result, ' did not match the expected.');
        }
    }

    [SysTestMethod]
    public void testMethod2()
    {
        boolean beforeBatch = isRunningOnBatch();
        boolean beforeinterative = hasGUI();

        container beforeResult = [beforeBatch, beforeinterative];

        using (var batchHandler = new SysTestBatchExecutionWrapper())
        {
            boolean isBatch = isRunningOnBatch();
            boolean isinterative = hasGUI();
            container result = [isBatch, isinterative];

            // Assert
            this.assertEquals([true /*isbatch*/, false /*isInteractive*/], result, ' did not match the expected.');
        }
    }


}

Helpful resources

Quick Links

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,129 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,154

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans