10. STRUCTURE
Setup: Put the Unit Under Test (UUT) or the overall test system in the state needed
to run the test.
Execution: Trigger/drive the UUT to perform the target behavior and capture all
output, such as return values and output parameters.
Validation: Ensure the results of the test are correct.
Cleanup: Restore the UUT or the overall test system to the pre-test state.
http://en.wikipedia.org/wiki/Test-driven_development#Test_structure
13. GIVEN-WHEN-THEN
Story: Returns go to stock
In order to keep track of stock
As a store owner
I want to add items back to stock when they're returned
Scenario 1: Refunded items should be returned to stock
Given a customer previously bought a black sweater from me
And I currently have three black sweaters left in stock
When he returns the sweater for a refund
Then I should have four black sweaters in stock
14. CUCUMBER
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two number
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
15. CUCUMBER
Given /I have entered (.*) into the calculator do
calculator = new Calculator();
calculator.push(n);
end
32. JASMINE
Suites & specs
describe("A suite is just a function", function() {
var a;
it("and so is a spec", function() {
a = true;
expect(a).toBe(true);
});
});
39. JASMINE
Clock
beforeEach(function() {
timerCallback = jasmine.createSpy("timerCallback"); //create spy
jasmine.Clock.useMock(); //use wrepper of system timer
});
it("causes a timeout to be called synchronously", function() {
setTimeout(function() {
timerCallback();
}, 100);
expect(timerCallback).not.toHaveBeenCalled();
jasmine.Clock.tick(101); //make time to go
expect(timerCallback).toHaveBeenCalled();
});
66. IRL, 100% COVERAGE IS A LIE
legacy & untestable code
permissive tests
not applicable to functional testing
67. MUTATION TESTING
Who tests tests?
Coverage is paramount! (it isn't)
Mutations: remove lines, alter operators, rename identifiers
The Future of Unit Testing