5

I'm currently working on a project and have noticed a colleague has started adding integration tests into unit test files. I'm considering taking them out, and putting them in a new project. Is this a good idea?

christiaantober
  • 251
  • 3
  • 10
Leigh Ciechanowski
  • 1,297
  • 17
  • 33
  • It depends. But normally, if that can be done without major edits, it sounds like there might be a problem with your project structure and/or architecture. Impossible to judge without closer inspection. – too honest for this site Mar 28 '18 at 22:50
  • According to Microsoft Docs: "Separate unit tests from integration tests into different projects. Separating the tests: - Helps ensure that infrastructure testing components aren't accidentally included in the unit tests. - Allows control over which set of tests are run." Source: https://learn.microsoft.com/en-us/aspnet/core/test/#aspnet-core-integration-tests – dario Mar 27 '23 at 16:01

3 Answers3

3

Depends on your test framework and continuous integration environment and whether you want to execute your integration tests with your unit tests.

Test frameworks like MbUnit, NUnit and MSTest support the concept of tagging tests with categories, meaning you could indiciate which tests were integration tests by marking them with their own category, ie "Integration". Categories make it possible to keep both sets of tests in the same project but use configuration settings to control which set of tests are run on the build server.

Personally, I like to split them out into separate projects only when necessary. For example, I might split then into their own project if the integration tests required their own special project dependencies or if I wanted to simplify the configuration of the build server such that integration tests are only run periodically.

bryanbcook
  • 16,210
  • 2
  • 40
  • 69
2

Depends on the scope of a "project". The integration tests for the components of a single project should be within the project. The tests testing the integration of multiple projects with each other should be a separate project.

thiton
  • 35,651
  • 4
  • 70
  • 100
  • Okay currently each project has a corresponding test project, these test projects have test classes within them. Each test class now has a mixture of integration and unit test methods. I'm thinking of moving the integration test methods out and into a new project. Would you agree this is a good thing to do? – Leigh Ciechanowski Dec 28 '11 at 16:05
  • 1
    Rather move the unit tests into the code project. Always keep unit tests as close to the actual source code as possible. – thiton Dec 28 '11 at 16:08
  • 2
    Hmm not sure if I like the idea of having test in with the production code. Check this out http://stackoverflow.com/questions/347156/do-you-put-unit-tests-in-same-project-or-another-project – Leigh Ciechanowski Dec 28 '11 at 16:15
  • @LeighCiechanowski: This question is for C#. Any build system worth its salt should support multiple executables per project and a `check` target, like automake does out of the box. The C# build system doesn't seem to, so I would consider the question you linked a workaround around a broken build system. – thiton Dec 28 '11 at 16:16
0

It is my opinion that int tests and unit tests should be separate files. You don't know when a class in your SUT will be swapped out. Separate unit tests reduce the refactoring needed.

Dave
  • 4,184
  • 8
  • 40
  • 46