3

If I have a Solution with a Project with Production code, where do I do the Unit tests? Do I put them in a whole new Solution and reference the Release version of my .dll?

I am using Asp.Net Core 1.1, C#. I have a "regular" MVC project, and I have a Core Web API as well I'd like to test.

I don't think this question is unique for C# or Visual Studio, but that is what I am using.

4
  • You put them into a different project. On your Release build, you can omit the test project, since the production environment will never need it. Mar 6, 2017 at 18:08
  • Same solution, right?
    – johnny
    Mar 6, 2017 at 18:09
  • Yes, same solution. Mar 6, 2017 at 19:41
  • If you come up with a naming convention one can easily omit the test projects from the package deployment. Example: MyProject.dll => MyProjectTests.dll Any Dll ending in Tests is not included in the package. We actually deploy several of our test projects as the tests are not unit tests and are run as part of a post deployment activity.
    – Jon Raynor
    Mar 6, 2017 at 21:13

1 Answer 1

2

I'm going to assume you're using the csproj (msbuild) version. At this point, project.json will be going away soon.

Here's a pretty standard project structure.

app
  |- app.sln
  |__
  |   |-project 
  |   |__
  |       | project.csproj
  |
  |__
      |-project.tests
      |__
          |-project.tests.csproj

Then in your project.tests.csproj, you add a ProjectReference element to reference the project under test.

<ProjectReference Import="..\project\project.csproj" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.