Does using touching a database mean a unit test is an integration test even if you are using fixtures?

If so, what are the alternatives to write a unit test when you need to use models as a part of a test in a CRUD app (e.g. Ruby on Rails)?

  • 2
    What sort of "fixtures" would you be referring to? Fixtures that contain a database? Mar 8, 2018 at 4:53
  • Integration testing is the phase in software testing in which individual software modules are combined and tested as a group. en.wikipedia.org/wiki/Integration_testing Mar 8, 2018 at 4:54
  • 4
    Does it really matter? Mar 8, 2018 at 5:04

1 Answer 1


A test fixture is the constraining of the parameters around a set of tests. In other words, setting up mocks, input data etc that will be shared by a number of tests are part of a test fixture.

People endlessly debate what’s a unit test and what’s an integration test. For me, the only useful definition I’ve come across is that, if a test can be isolated (ie it has no side effects and can be run in parallel), then it’s a unit test. Everything else is an integration test. Others might disagree with this, eg by viewing testing a method in isolation as a unit test and everything else as integration tests.

Regardless of which definitions you favour, it’s clear that the terms are unrelated to test fixtures. So no, using a fixture does not transform a unit test into an integration test.

  • 4
    This if a test can be isolate (ie it has no side effects and can be run in parallel), then it’s a unit test should be bolded
    – Fabio
    Mar 8, 2018 at 7:56
  • 3
    And I will add: unit tests should be fast.
    – Fabio
    Mar 8, 2018 at 7:58
  • 1
    And I will improve: all tests should be fast
    – Mariyo
    Mar 13, 2020 at 9:52
  • 1
    @Mariyo, all tests should be as fast as possible. But sometimes that may not fit into normal definitions of "fast". Overnight test runs of hours can still be of benefit for example as finding a bug overnight is better than finding it in production, weeks later.
    – David Arno
    Mar 13, 2020 at 10:15

Your Answer

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

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