简体   繁体   中英

How to test Program.Main in TestMethod in MSTest project

I have a simple test method so far just to call the static method Main in Program.cs on a netcore mvc app.

My assert is never hit and the test just keeps running in the test explorer, even after 5 or 10min. Is it because the Program needs termination or is my implementation wrong for the test?

Advice appreciated

Thanks Rob

[TestClass]
public class ProgramTests
{
    [TestMethod]
    public void ExecMain()
    {
       var args = new string[] { };

       Program.Main(args);

       // never hits test condition and test keeps running
       Assert.IsTrue(true);
    }
}

测试资源管理器

Your implementation is not wrong since you are following the AAA practice (Arrange, Act, Assert).

It seems, however, that you have not figured out what is to be tested. Are you expecting Program.Main to run forever? or should it terminate in some point? (something or someone should probably cause termination.)

If you can find out how to cause termination, you should do it in your test and then make the assertion (which obviously reflects your expectations from termination.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM