Understanding the difference between test-first and test-driven,

I have had conversations about this topic in the past, and I think I might know the answer, but I could not formulate it correctly.

Here is what I think I know:

I suspect that you are testing first, not testing, if you already have an idea how everything will work before writing tests, so first you write tests that will test your idea before implementing your idea. That is, first you go about implementation and control how the tests look.

If you are set up for testing, you are trying to get a test to manage the implementation. You are writing a test for some behavior that you want, and not for a biased implementation idea, so you need to come up with an implementation at the "refactoring" stage to pass the test well.

My questions:

  • Did I understand this correctly?
  • How do you get into the test way of thinking from the test-first thinking, when it is natural for most developers to start exploring solutions in their minds before they even reach for the keyboard?
+6
source share
4 answers

A key aspect of test development is that you do not implement functionality that is not required to pass the test. The first test is just a test record before implementing the functionality. This is mainly done to ensure that the test will indeed fail if there is no function. Test-based development involves a test-based approach, but not vice versa.

+4
source

I think you well understood and clearly formulated the difference between testing and testing, and, as Bjorn points out, all test developments must be the first. To your question about how to switch from test to test-oriented thinking, I suggest several times to perform a relatively simple exercise (for example, implement Range or Rectangle), trying to come up with a different implementation each time. The first time you come up with what you are thinking now - and it is not caused by trials, as you indicate. Next time you will not be able to use what you are thinking now; you will have to turn to something else, and some of these achievements will occur if the test fails. Perhaps for the third time, you will begin to give up your preconceived decisions and just do what makes you make you - and you are on the way to thinking based on tests.

If the exercise is not to your taste, try writing your first test sooner. Do not analyze in advance. Just taking the problem upon yourself, first write a test. Now you can think of a problem with the “looking over your shoulder” test. It will be inconvenient for some time, but due to discomfort a new way (and, I think, good) should appear to look at the problems.

+1
source

Writing a test suite before implementation allows you to make unit tests for public methods. So, the real implementation of what is happening is hidden from the test. You code an abstract, not an implementation, which is a good thing (TM). You accept abstract terms and concepts - tests will determine what your public methods will be. So a test test means that your tests will run the API. On the contrary, you call the test first.

0
source

The difference lies in discovering roles and interfaces.

  • If you write your tests before writing code, you get the Test-First badge.
  • If you are testing the first one and listening to your tests to find out what types / roles / interfaces are needed and to grow your design using JIT refactoring, then you will get an icon with test management.

At the first test, you will probably move on to design (which may / may not be the simplest / best choice based on your skill) before writing tests. Testing - It is also easy to test for poor existing design, but progress will be slow. You will likely get complex code and slow write tests.

IMHO Test-driven helps me write simple projects that are easy to test .

How to enter into thinking ?: This is the part where you need self-discipline and practice. Yes, it’s hard to keep your mind from racing to making decisions. +1 Karl for drawing a code-Kat in search mode, make different options and see how it ends. With a few under your belt it gets easier ... TDD actually makes you “focus” on one thing at a time.

0
source

Source: https://habr.com/ru/post/898755/


All Articles