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

前端 未结 7 1151
予麋鹿
予麋鹿 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:04

    When a unit test fails (I mean a real unit test that tests a method in isolation using mocks), it tells you what "unit" has a problem. When an acceptance test fails, it tells you what "feature" has a problem, not where the problem is located.

    0 讨论(0)
  • 2021-02-12 12:04

    I've been practicing Cucumber/RSpec for the past half year or so doing BDD.

    First of all BDD is not easy to get into, it will feel unnatural at the beginning.

    But once you get into it, there's no other way to do programming.

    To answer your question. To test Javascript you'll need a javascript driver that can be used by Capybara which is used by Cucumber.

    capybara-webkit is what all the cool kids use now these days

    There's one important thing to note.

    Integration tests are slow.

    And unit tests are fast, but can be slow, so it's important you use the right database cleaner and you write good tests that have good isolation.

    My test setup which I'm extremely happy with:

    Guard for loading spork Spork for faster tests Cucumber for integration testing capybara-webkit for javascript testing RSpec for unit testing

    I don't do view tests and controller tests as these are redundant in my opinion as good knowledge of XPATH willl have you writing remarkable tests that even cover your page layout and structure.

    0 讨论(0)
  • 2021-02-12 12:06

    When you create a rails app you get functional, interation, and unit tests by default. Cucumber is an additional test it is a way to also test the experience that your user will have. When they click the button labeled "go" they should see "success" rendered rather than a 404. This will make sure that nothing you do accidentally messes up the user experience, and that from the top to bottom your app works for the most common use cases you can think of. The other tests are meant to insure that nothing goes wrong, and that you have inspected ever model and method with a microscope. It may be possible to replicate unit tests in their entirety with cucumber, but it would be painful (and crazy slow to execute, especially if you're using selenium). The best time to write tests is when you're developing code, and the quickiest and easiest way to do that, is by using in the built-in rails testing and maybe some additional help such as shoulda, rspec, also i'm a huge fan of factory-girl. If you haven't already checked it out www.railscasts.com has a great intro to cucumber, and rspec, and factory-girl, ... I know this question has already been answered (it's no) but this is my two cents. Good luck coding!!

    0 讨论(0)
  • 2021-02-12 12:10

    From my experience, Cucumber and Rspec have different appeal. Rspec appeals to me from a developer perspective because its easy to write and provides very quick feedback when something breaks. Cucumber does not appeal to me as a developer because it does not run as quickly as Rspec. However, Cucumber does appeal to me as a business stakeholder since it provides full coverage of entire features.

    Do yourself a favor and keep writing unit tests.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-12 12:21

    Personally I don't think that you should stop writing unit tests. As an acceptance testing tool, Cucumber should replace your functional tests and, if you writing, view tests.

    Cucumber features are supposed to be simple and coupled to the real user's value a given feature has.

    0 讨论(0)
提交回复
热议问题