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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Unit Tests for Main method

(0) ShareShare
ReportReport
Posted on by 35

Hello all :) 

So i have a class with three methods , main() , construct(), & calc() .

I wrote a test class and in there set up unit tests for all of the branches in calc() & one additional test for the construct method. And with that leaving me with a point to how to test the main method? 

In there I have just basic code. 

So this is maybe dumb but any suggestions on how to test this class without duplicating the code from the test method for calc? 

 public static void main(Args _args)
    {
        ProcessClass obj = ProcessClass::construct();
        obj.calc(_args);
    }

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    By testing the main method do you mean executing it?

    To execute the main method, you can create an action menu item and specify the class for the main method on it or you can directly execute this class using the following URL in your browser:

    https://FinOpsBaseURL/?cmp=YourCompany&mi=SysClassRunner&cls=YourClassName

    Regards,

    Kamal

  • AnawI Profile Picture
    35 on at

    So, to be honest , i don't think i understand you completely .

    I need to write unit tests from which i will execute the main method , so with code.

  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    Running main() method from a test class is trivial: ProcessClass::main(new Args()).

    But the question is what you would test by it. What would be the "evaluation" part of your unit test?

    If you know what you want to test, then do it. If you don't know, ask yourself about the value of this test. Isn't it just to get a higher number of code coverage and not about bringing business value?

    If you want to test that main() calls calc() but not to actually execute logic in calc(), you would need something like a test stub. The currenct implementation would require ProcessClass::construct() to return the test stub instead of the actual ProcessClass class instance. It can be done, but it's quite cumbersome without any mocking framework.

    It again brings the question of the value of the test. You may end up with a lot of work just to run a test that gives you little information.

  • AnawI Profile Picture
    35 on at

    Thank you so much, this cleared a lot of questions i had.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 616

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 460 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 331 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans