4. JUnit Test Example @ Test public void simpleAdd() { Money m12CHF = new Money ( 12 , "CHF" ); Money m14CHF = new Money ( 14 , "CHF" ); Money expected = new Money ( 26 , "CHF" ); Money result = m12CHF . add(m14CHF); assertTrue(expected . equals(result)); }
5. JUnit Test Fixture Setup public class MoneyTest { private Money f12CHF; private Money f14CHF; private Money f28USD; @Before public void setUp () { f12CHF = new Money ( 12 , "CHF" ); f14CHF = new Money ( 14 , "CHF" ); f28USD = new Money ( 28 , "USD" ); } }
6.
7.
8.
9. Cucumber Example Feature: Contact Us As an anonymous user I want to be able to send a message So that I can receive support or get an answer to a question Scenario: Load Form Given I am on "home page" When I follow "Contact Us" Then I should see "Please use the following form" Scenario: Submitting form Given I am on the "contact us page" When I fill in "contact_handler[email]" with "me@example.com" And I fill in "contact_handler[subject]" with "Help" And I fill in "contact_handler[body]" with "Content" And I press "send" Then I should see "Thanks for your message."
10.
11.
12. An RSpec Example You: Describe an account when it is first created. Customer: It should have a balance of $0. describe Account, "when first created" do it "should have a balance of $0" do ... end end When you run this example, RSpec can provide a report like this: Account when first created - should have a balance of $0