Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I Wrote one test case for executing main method in Program.cs page in .net core.
This method hitting but not completing.Still routating with out pass or fail.that assert also not hit

What I have tried:

public class ProgramTest
    {
        [Fact]
        public async  void MainTest()
        {

            try
            {
                
                    Program.Main(new string[0]);
            }
            catch(Exception ex)
            {

            }            

            Assert.Null(null);
        }
    }
Posted
Updated 30-Sep-19 4:56am
Comments
F-ES Sitecore 28-Jun-19 10:35am    
If the code is hanging it is probably because it is waiting for Main to finish. That is not a unit test anyway, what are you testing?

Testing main method is a bad idea.
First of all, there are no direct outputs to verify because main returns void (or Task)
Secondly, if your goal is to verify the side effect method produces, you cannot mock your dependencies. Which in turn makes your test more of an integration test.
Extract logic you want to test into a class and test it.
 
Share this answer
 
You cannot catch any exception in an async void method anyway.
Avoid async void methods[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900