Does cucumber do away with the need to write unit tests?

前端 未结 7 1152
予麋鹿
予麋鹿 2021-02-12 11:35

I am a little confused by the sheer number of testing frameworks available for Ruby/ROR.

I have recently watched the Cucumber Railscasts and found them very interesting.

7条回答
  •  灰色年华
    2021-02-12 12:13

    Use Cucumber at a high level to describe what a user should be able to see and do. Use RSpec, Test:Unit, Shoulda, etc. to write unit tests. Straight from the horse's mouth:

    When you decide you want to add a new feature or fix a bug, start by writing a new feature or scenario that describes how the feature should work. Don’t write any code (yet).

    ...

    This is when you start writing code. Start by writing a couple of lines of code to address the failure you got from Cucumber. Run cucumber again. Repeat and rinse until you’re happy with your feature. When you get down to nitty gritty details, drop down one abstraction level and use RSpec, or any Ruby testing framework, to write some specs/tests for your classes.

    Cucumber is made to test your whole stack, together, as opposed to 'units'.

    You need to decide where to draw the line, but a lot of under the hood stuff probably wouldn't be covered in a cucumber test. Say when signing up, I fill out a form, with my name, email, phone number, etc. A unit test might check to see that a new User will also create a new TelephoneNumber. From the user's perspective, they don't really care that it creates a new TelephoneNumber, they care that once they've signed up, they have an account and can see their telephone number.

    I don't have too much experience writing cucumber tests (not yet), but I hope this helps a bit.

提交回复
热议问题