关于CS169 TDD(Test Driven Development)

本文介绍了如何在Rails应用中设置RSpec与Cucumber的集成,包括安装所需gem、配置Gemfile以及运行Cucumber和RSpec的基本步骤。确保正确安装gem并配置环境以进行高效的测试和自动化测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

*一些视频:  http://vimeo.com/34754907


1. RSpec
2. Unit test
3. DSL:   Domain-specific language, examplesso far, migrations, regexes, SQL
4. "should_receive" to mock up a method.


5. 一篇关于RSpec的中文简单介绍: http://ruby-china.org/topics/2848
6.  代码覆盖分析工具SimpleCov: https://github.com/colszowka/simplecov


如何设置Cucumber + RSpec:

group :test, :development do
  gem 'cucumber-rails'
  gem 'cucumber-rails-training-wheels' # some pre-fabbed step definitions  
  gem 'database_cleaner' # to clear Cucumber's test database between runs
  gem 'capybara'         # lets Cucumber pretend to be a web browser
  gem 'launchy'          # a useful debugging aid for user stories
end

Make sure your Gemfile contains the above codes,  as well as the line
gem 'rspec-rails'
within the group :test, :development block.

运行
bundle install --without production
来保证gem都安装了。

If necessary, set up the Cucumber directories (under features/) and the RSpec directories (under spec/), allowing overwrite of any existing files, by running the commands:

rails generate cucumber:install capybara

rails generate cucumber_rails_training_wheels:install

rails generate rspec:install

Double-check that everything was installed by running the tasks:

rake spec
rake cucumber
因为features和specs还没写,配置正确的话, 以上两条命令应该是正确运行并且提示没有test运行。 RSpec根据版本不同,也有可能提示找不到 '_spec.rb' 文件。

Chapter 1, Why Should I Care for Test-Driven Development?, spells out our goal of becoming a Java developer with a TDD black belt. In order to know where we're going, we'll have to discuss and find answers to some questions that will define our voyage. Chapter 2, Tools, Frameworks, and Environments, will compare and set up all the tools, frameworks and environments that will be used throughout this book. Each of them will be accompanied with code that demonstrates their strengths and weaknesses. Chapter 3, Red-Green-Refactor – From Failure Through Success until Perfection, will help us develop a Tic-Tac-Toe game using the red-greenrefactor technique, which is the pillar of TDD. We'll write a test and see it fail; we'll write a code that implements that test, run all the tests, and see them succeed; and finally, we'll refactor the code and try to make it better. Chapter 4, Unit Testing – Focusing on What You Do and Not on What Has Been Done, shows that to demonstrate the power of TDD applied to unit testing, we'll need to develop a remote-controlled ship. We'll learn what unit testing really is, how it differs from functional and integration tests, and how it can be combined with test-driven development. Chapter 5, Design – If It's Not Testable, It's Not Designed Well, will help us develop a Connect 4 game without any tests and try to write tests at the end. This will give us insights into the difficulties we are facing when applications are not developed in a way that they can be tested easily. Chapter 6, Mocking – Removing External Dependencies, shows how TDD is about speed. We want to quickly demonstrate some idea/concept. We'll continue developing our Tic-Tac-Toe game by adding MongoDB as our data storage. None of our tests will actually use MongoDB since all communications to it will be mocked. Chapter 7, TDD and Functional Programming – A Perfect Match, dives into the functional programming paradigm and how TDD could be applied when programming in that way. We'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值