ラマンと申します。 私の出身はインドで2年前に日本に来ました。 日本語があまり得意ではありませんので、英語で書かせてもらいます。
Step - 1 :: Write all test codes which you can think in the starting that fails based on the requirements of the actual function . Step - 2 :: Modify the code and test it again . Step - 3 :: Once each test passes then do refactoring . Step - 4 :: Repeat step 1 to step 3 until all test are passed . Step - 5 :: You can add test later if you did not think in the starting and repeat Step 1 to Step 3 .
This representation is divided into three zones. Red :: In this zone, developer will write the code then test will fail. Green:: In this zone, developer modify the code and test will pass. Blue:: In this zone, developer will refactor the code.
No, TDD is independent of any programming language. This means, you can use in php, javascript, go and other programming language.
length.go
and write the logic which will fail .package length // Check String Length should be between 6 and 10 func CheckStringLength(str string) bool { return false }
length_test.go
which will use logic from length.go
package length import ( "testing" ) func TestCheckStringLength(t *testing.T) { var isValid bool isValid = CheckStringLength("test123") if isValid == false { t.Error("The string length is incorrect") } }
length.go
package length // Check String Length should be between 6 and 10 func CheckStringLength(str string) bool { isValidStringLength := false if len(str) > 5 { isValidStringLength = true } if len(str) > 10 { isValidStringLength = false } return isValidStringLength }
length.go
package length // Check String Length should be between 6 and 10 func CheckStringLength(str string) bool { if len(str) > 5 && len(str) < 11 { return true } return false }
Like this, if you want to add or missed any test case then add the function and test the code after adding test case. This will verify that the previous added function works well irrespective how many test case you will add.
https://en.wikipedia.org/wiki/Test-driven_development https://www.valtes.co.jp/qbookplus/1069 https://golang.org/pkg/testing/