What is test development? Do I need to have initial projects?

I am very new to TDD, have not yet started using it. But I know that we must first write a test and then the real code in order to pass the test and reorganize it to a good design.

My concern about TDD is where it fits into our SDLC. Suppose I received a requirement to create an order processing system. Now that I have no model and design for this system, how can I start writing tests? Don't we need to define entities and their attributes in order to continue? If not, is it possible to develop a large system without any design?

+7
tdd
source share
9 answers

There are two levels of development for TDD, ATDD or acceptance testing and normal TDD, which is driven by unit tests.

I believe that the relationship between TDD and design depends on some “flexible” concept that the source code is software product design. Many people reinforce this by translating TDD as Test Driven Design rather than development. This is important because TDD should be considered as having much more in common with design management than testing. Acceptance and unit tests at the end of this effect are a good side effect.

I can’t say too much about where it fits into your SDLC without knowing more about it, but one nice workflow:

For each user story:

  • Write acceptance tests using a tool such as FitNesse or Cucumber , this will determine which desired outputs are for these inputs, from the point of view that the user understands. This level automates specifications or may even replace documentation specifications in ideal situations.

  • Now you will probably have a vague idea of ​​what kind of software design you might need, since classes / behavior, etc. is coming.

  • For each behavior:

  • Write a failed test that shows how the calling code you would like to use the class .

  • Implement behavior that makes the test pass

  • Refactoring both test and actual code to reflect good design.

  • Proceed to the following behavior.

  • Go to the next user history.

Of course, all the time you will be thinking about the evolving design of a high-level system. Ideally, TDD will lead to a flexible design at lower levels, which allows you to develop an appropriate design when you go, rather than trying to guess it at the beginning.

+8
source share

It should be called Test Driven Design , because that's what it is.

There is no practical reason to separate design from a specific phase of a project. Design happens all the time. Starting with an initial discussion with interested parties, by creating a user story, evaluating, and then, of course, during TDD sessions.

If you want to formalize a design using UML or something else, that's fine, just keep in mind that code is design and everything else is just an approximation. And remember that YAGNI applies to everything, including project documents.

+4
source share

The write test first makes you think about the problem domain first and act as a kind of specification. Then, in the second step, you move into the solution area and implement the functionality.

TDD works iteratively:

  • Identify your original problem domain (may be a small, evolutionary prototype)
  • Implement it
  • Extension of the problem area (adding functions, creating a prototype)
  • Refactoring and its implementation
  • Repeat step 3.

Of course, you need to have a vague architectural vision (technology, layers, non-functional requirements, etc.). But features that add value to your application can be perfectly added to TDD.

See related TDD question : good for a starter?

+3
source share

With TDD, you don't really like the design. The idea is that you must first find out what you need before starting with a useful design. Tests ensure that you can easily and reliably change your application when the time comes that you need to decide on your design.

Without TDD, this happens: you create a design (which is probably too complex in some areas, plus you forgot to accept some important facts because you did not know about them). Then you start to implement the design. Over time, you will realize all the flaws of your design, so you change it. But a design change does not change your program. Now you are trying to change your code in accordance with the new design. Since the code was not written to be easy to change, it will ultimately fail, leaving you with two projects (one broken and the other in an unknown state) and a code that also doesn't work.

To get started with TDD, include your requirements in the test. To do this, ask: "How do I know if this requirement is met?" When you can answer this question, write a test that will answer this question. This gives you an API that your code must adhere to. This is a very simple design, but one that a) always works, and b) that is flexible (because you cannot check inflexible code).

Also, starting with the test, you will turn into your own client. As you try to make the test as simple as possible, you will create a simple API that will do the test work.

And over time, you will learn enough about your problem area to be able to make a real design. Since you have many tests, you can change your code to fit your design. Without a final violation of anything along the way.

What is the theory :-) In practice, you will encounter several problems, but this works very well. Rather, it works better than anything else I came across.

+2
source share

Well, of course, first you need a reliable functional analysis, including a domain model, not knowing what you will need to create, first of all, it is impossible to write your unit tests.

+1
source share

I use test development for programming, and from my own experience, it helps to create more reliable, oriented and simpler code. My recipe for TDD goes something like this:

  • Using the unit-test framework (I wrote my own) to write code how you want to use it, and tests to provide return values, etc. true. This ensures that you only write the code that you are going to use. I also add some more tests to check edge cases.
  • Compile - you will get compiler errors !!!
  • For each error, add declarations until you get compiler errors. This ensures that you have minimal declarations for your code.
  • Link - you will get linker errors !!!
  • Write enough implementation code to remove linker errors.
  • Launch - you will complete module testing. Write enough code for the test to succeed.

You are done at this point. You have written the minimum code necessary to implement your function, and you know that it is reliable because of your tests. You will also be able to detect if you violate the situation in the future. If you find any errors, add a unit test to check for this error (you may not have thought about the edge case). And you know that if you add more functions to your code, you will not make it incompatible with existing code that uses your function.

I like this method. Makes me feel warm and fuzzy inside.

+1
source share

TDD assumes that for starters there is some existing design (external interface). You must have some kind of design to start writing a test. Some people will say that TDD itself requires less detailed design because the act of writing tests provides feedback on the design process, but these concepts are usually orthogonal.

0
source share

You need some form of specification, not a design form - design is how you are going to implement something, the specification is about what you are going to implement.

The most common form of specifications that I have seen in TDD (and other flexible processes) is user stories - an informal kind of “use case”, which is usually expressed in a few stereotyped English sentences, such as “How can I” ( the form of user stories is more or less rigid depending on which style / process is used).

For example, “As a customer, I can start a new order,” “As a customer, I can add an entry to my existing order,” etc., it might be typical if this is what your “order” (user stories would be very different if the system was not "self-service" for users, but rather intended to be used by sales representatives who are available on behalf of users, of course - not knowing what kind of login system means that it is impossible to act wisely, so I say that you need some kind of specificity This is what the system is going to do, although, as a rule, it is not a complete idea of ​​how it will do it).

0
source share

Let me share my opinion:

If you want to create an application, try checking it, for example, checking the values ​​of the variables that you create using code verification, to quickly release the button you can click on and execute part of the code, and then a dialog box will appear. to show the result of the operation, etc. TDD changes your mindset.

Typically, you simply rely on a development environment such as Visual Studio to detect coding and compilation errors and somewhere in your mind, you know the requirements and just coding and testing using buttons and pop-ups or code checking. This is a development driven by syntax debugging. but when you work with TDD, this is "semantic debugging-based development" because you first write down your thoughts / goals for your application using tests (which are a more dynamic and repeatable version of the whiteboard) that checks the logic (or "semantic ") of your application and fails whenever you get a semantic error, even if your application passes a syntax error (after compilation).

In practice, you may not know or do not have all the information necessary to create an application, since TDD forces you to write tests first, you are forced to ask more questions about the operation of the application at an early stage of development than to build a lot just to find out what a lot of what you wrote is not required (or does not allow at the moment). you really can not waste your precious time on TDD (although at first glance this may not seem like that)

0
source share

All Articles