0

I'm using Visual Studio 2015. Creating a stateful API. Because it's using Sessions I cannot use Unit Testing directly to my Controller classes for validation. I need to use HTTP calls.

But when running my Unit Test it doesn't run my project so the HTTP call doesn't find the url http://localhost:54916/api/register

If I run my project and then goto the menu for running Unit Tests it's disabled.

When running my Unit Tests how can I first run the project so that the web/database is online?

roady
  • 597
  • 2
  • 6
  • 20

1 Answers1

0

Tests that run against real web/database are integration-tests rather than unit-tests.

For unit-testing I'd mock the networking\database out of your code in order to test pure logic without relying on the environment that you run on.

For integration-tests, Id create a setup that runs before the tests begin and create the environment that your tests rely on. Of course a teardown that runs after all tests finished their execution that destroys the environment created in setup. *The setup can be a method special method with dedicated attribute (MSTest examples) or a build action in your build\CI.

Community
  • 1
  • 1
Al.exe
  • 483
  • 3
  • 6