Testing - Behavior Driven Development
BDD vs. TDD
The trouble with writing TDD testing is that too many developers focus on “How” when writing their unit tests, so they end up with tests that only confirm what the system does. It is really a feature driven approach to TDD. Some even say that BDD is just TDD done correctly.
BDD focuses on telling stories.
Side Note:
Unit Tests
- Tests that a relatively small piece of code is doing what is is intended to do.
- These follow the white box method and testing the inputs and the outputs of a test.
Integration Test
- This is done to demonstrate that different pieces of the system work together. Integration tests cover whole applications and require much less effort to implement.
Cucumber
- Does not actually write code, but it provides syntax and context for them to actually be written.
Feature: Manage Articles
In order to make a blog
As an Author
I want to create and manage articles
Scenario: Articles List
Given I have articles title Pizza, Breadsticks
When I go to the list of articles
Then I should see “Piazza
And I should see “Breadsticks”
Capybara is used for high level tests in addition to Test Driven Development to simulate how a user interacts with an application.
- It Clicks on things.
The DSL (Domain Specific Language)
Navigation - visit(‘/home’)
Click Links and Buttons - click_link(‘id-of-link’)
Interacting with Forms - fill_in(‘First Name’, :with => ‘Thomas)
Querying - page.has_selector(‘table tr’)
Finding - find_link(‘hello’).visible?
Scoping
within(‘li#movie’) do
fill_in ‘Name’, :with => ‘Jimmy’
end
Scripting (JavaScript)
page.execute_script(“$(‘body’).empty()”)
Ajax
click_link(‘foo’)
click_link(‘bar’)
page.should have_content(‘baz’)
The default wait time is 2 seconds between requests, but it can be changed.
Capybara.default_wait_time = 5
No comments:
Post a Comment