3

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? – Robert Harvey Mar 8 '18 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 – Robert Harvey Mar 8 '18 at 4:54
  • 4
    Does it really matter? – whatsisname Mar 8 '18 at 5:04
7

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.

  • 2
    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 '18 at 7:56
  • 3
    And I will add: unit tests should be fast. – Fabio Mar 8 '18 at 7:58

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.