TDD and Unit Test, both are the same thing and have the same purpose?

Asked

Viewed 557 times

8

Always when I read about TDD (Test Driven Development) it is related to Unit test, It makes me believe that TDD is the same as Unit test, and I don’t know if my definition is correct in relation to my point of view. Maybe I’m confusing the terms and mixing the concepts.

TDD and Unit test are separate things? If so, what are the differences between them and what is the purpose of each in particular?

  • 1
  • 2

    @Bigown I read the answer of this your question, are so many test concepts that confused me even more, so I decided to also ask a question more directed to TDD and Unit Test where is the point that causes me more confusion, because both are similar. I don’t think it’s duplicate, but it’s at the community’s discretion.

1 answer

8


These are different concepts. TDD is a software development philosophy: to implement any functionality (or make changes to code), you:

  1. Creates a (or more) test(s), which will probably be unitary, but not always
  2. Run the test, noting that it will fail (you may also need to implement something like mocks for the compilation to work)
  3. Implements functionality / change in program
  4. Run the test again, check that it is now passing.

Unit tests are just one component of the TDD (step 1 of the above process) - in every TDD process, you will have (many) unit tests, but not only them: integration tests, with or without mocks, are also needed.

And you can use unit tests even without TDD. If you do not believe in this philosophy (and many do not follow it), then you can develop the software in the "traditional" way, and post-facto implement the tests (unitary or not).

  • A fifth important step is missing: the Refactoring. In addition, it is not a "or more" test, it is only a test in each cycle, and one can eventually skip the Refactoring before starting the next cycle (technique called "triangulation"). In addition, excellent response.

  • Vc said that the tests are probably unitary, but not always this occurs, in this case what is the type of test that is associated with TDD which is not a unitary test?

  • Integration tests, for example. By definition, unit tests only test a "unit". If you found a bug in your system caused by a drive passing a wrong value to another drive, an iteration of the TDD would be the implementation of a test with these two drives (which would fail because of the bug), fix the bug, and then verify that the test passed. As this test is validating two "units", it cannot be strictly considered a unit test.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.