Skip to content
This repository has been archived by the owner on Nov 9, 2018. It is now read-only.

Integration tests in separate project #237

Closed
nojaf opened this issue Oct 14, 2016 · 2 comments
Closed

Integration tests in separate project #237

nojaf opened this issue Oct 14, 2016 · 2 comments

Comments

@nojaf
Copy link

nojaf commented Oct 14, 2016

I tried to set up some end-to-end tests following https://docs.asp.net/en/latest/testing/integration-testing.html.

The docs don't seem to assume that the test assembly is a separate project in the test folder.
I did a basic test if my default route returns a 200.

    public class IndexPageTest
    {
        private readonly TestServer _server;
        private readonly HttpClient _client;

        public IndexPageTest()
        {
            _server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
            _client = _server.CreateClient();
        }

        [Fact]
        public async Task DefaultRoute_ShouldReturn_Ok()
        {
            var response = await _client.GetAsync("/");
            response.EnsureSuccessStatusCode();
        }
    }

When running this test it failed because my views and appSettings.json were not in the bin folder of the test project.

What is the best way to deal with this?

@nojaf
Copy link
Author

nojaf commented Oct 28, 2016

Tried to add it in my project.json but no luck

    "buildOptions": {
      "debugType": "portable",
      "copyToOutput": {
        "include": "../../src/MyProject/Views/",
        "mappings": {
          "./Views": "../../src/MyProject/Views/"
        }
      }
    }

Project structure:

rootfolder
  src
    MyProject
  test
    MyProject.Tests

@nojaf
Copy link
Author

nojaf commented Oct 29, 2016

Found a workaround by changing the content root

            char slash = Path.DirectorySeparatorChar;
            var contentRoot = $"..{slash}..{slash}..{slash}..{slash}..{slash}src{slash}MyProject";
            var webHostBuilder = new WebHostBuilder()
                .UseStartup<Startup>()
                .UseContentRoot(contentRoot);

@nojaf nojaf closed this as completed Oct 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant