How to learn TDD with Ruby?

后端 未结 7 1034
情深已故
情深已故 2020-12-24 02:07

I have been using ruby exclusively for about a month and I really love it. However, I am having an incredibly hard time using, or even learning TDD. My brain just doesn\'t f

相关标签:
7条回答
  • 2020-12-24 03:02

    The best way to learn TDD is by just doing it. I suggest you build a new project using TDD. This means don't write any non-testing code unless you have a failing test.

    It will make you think about writing tests: I want to write this code, how do I write a test for it so I can write it.

    It will show you the layered nature of testing. Instead of want a name that is required and can't contain numbers. you'll first test setting and reading a name, test requiring the name, test it shouldn't contain numbers, than think if it has more constraints and test those.

    Remember:

    • Write a test before you write the code
    • Make sure the test fails! It's important to know you're testing logic is correct
    • Before writing the next test make sure all tests succeed
    • You can always clean up your code, if the tests keep working you didn't change the design
    0 讨论(0)
提交回复
热议问题