1

Is there any ways to write unit test for Program cs file for ASP.NET Core Web API and similarly for startup class, just to show more code coverage for the entire app? It's shows 0% coverage for now.

enter image description here

5
  • 1
    That isn't something you need to test. Covering it just so that your numbers are 100% provides no value. Write the rest of the application and test that code. Commented Jan 15, 2022 at 12:43
  • 1
    You can call Main just like any other method, whether there's any value in doing so is up to you. In order to ensure the application starts up properly is typically done by integration tests or smoke tests. Commented Jan 15, 2022 at 12:43
  • Thanks @Matthew, could you share some code article on this. Appreciate @! Commented Jan 16, 2022 at 4:04
  • There is nothing really to unit test here. If the whole application really does what it should is an e2e or smoke test. Nothing you would do in a unit test. Commented Jan 17, 2022 at 15:04
  • ok Oliver, any code sample you can share for e2e/smoke which covers program and startup file test. Appreciate for your answer! Commented Jan 17, 2022 at 15:07

1 Answer 1

2

you can extract the configuration out in separate calls and expose them into func<> which is you are custom created and write the unit test for them . TIt is not recommended to test the framework code. you should do testing for your code only not for the framework. I hope you get the point correctly.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Priyanshu. I get the point, but do you mind to share bit code as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.