WHAT IS TDD :-
1. Test driven development (TDD) is developed which specifies and validates what the code will do
2. Test cases are created before code is written
3. The purpose of TDD is to make the code clearer, simple and bug free
4. TDD starts with designing and developing tests cases for every small functionality of an application
5. TDD instructs developers to write new code only if the test case of particular feature getting failed
6. There is a cycle which TDD follows :-
-> Write a test
-> Make it run
-> Change the code to make it right OR we can say to refactor the code
-> Repeat this process
7. Test-Driven Development as three steps :-
-> Red
-> Green
-> Refactor
8. So you don't have a piece of code, so first thing you would write is the first test condition for that particular thing
9. Let's I have a method which I have to write and I would probably identify the conditions which have to write and probably identify one of the conditions and write the test for it
10. So that's Red so because if you run that test the code would fail the test
11. Green is when you write the piece of code that is needed to make the test pass
12. So I had a failing test and now I write the code to make the test pass that's green so that's the step green
13. The last step is actually refactored where I need to make the code adhere to four principles of simple design if you don't know what four principles of simple design. So the third step is actually making the code better
14. One of the things about making the code better is to make it a date before principle of simple design at least and most important thing also is to keep it green that's basically it should just should always be passing while you refactor the code
15. Most important is refactor stage you can refactor both the test and the code so even the test is a piece of code which you are going to maintain over a period of time and it should be clear enough so you would go ahead and refactor the test as well and the code as well
16. So that's basically what tests reown development is all about there are three more logical to stay in development that's basically to say like how much code that you can write to make a test fail
LAWS OF TDD
So that's a four laws of test-driven development :-
-> The first law is no production code without failing this so if you don't see a red bar then you are not going to code so that's basically what it means if you write new piece of code only when you see the red bar so only when there is a failing test you write new code and when you add a new test it should be a small test you should not write probably five six conditions of this at the same time what the way it should be is you add a small piece of test probably one small condition
-> The next step you write just enough code to tear at make the test pass so as soon as you write the test you'd write the code which is needed to make that test passes you write a small test
-> Write the small piece of code to make it pass and you follow this in a cycle
-> So these are the three laws of TDD actually like I can act in a fourth law it says all these three steps like the three steps of TDD which is red green refactor usually you should be able to run within two minutes
CONCLUSION
1. In two minutes I should be able to do the three things that basically add a failing test right go to make it pass and then refactor
2. So regarding TDD there are few important things that you need to keep in mind. Make the right choice actually test-driven development is proven to be a success and it leads to maintainable code understandable code and it's known to improve your productivity the productivity improvement is more like after you get a little experience with testing and development.
0 comments:
Post a Comment