testing - is this even a thing?

11
Testing, Is This Even a Thing? NICK GEORGE SAM SCHNEIDER GTM SPORTSWEAR

Upload: nick-george

Post on 12-Feb-2017

133 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Testing - Is This Even a Thing?

Testing,Is This Even a Thing?NICK GEORGESAM SCHNEIDER

GTM SPORTSWEAR

Page 2: Testing - Is This Even a Thing?

Why Do We Need Tests?• “You know you are working on clean code when each

routine you read turns out to be pretty much what you expected.”–Ward Cunningham

• Symptoms:• Code Rot• Apathetic Developers• Code Breaking And Having No Idea Why

Page 3: Testing - Is This Even a Thing?

What is a Test?• An automated way to make sure your code does what

you think it does.• Unit testing involves breaking your program into pieces,

and subjecting each piece to a series of tests.

assert('Strings should equate', assert => { const testString = 'test'; equal(testString, 'test');});

Page 4: Testing - Is This Even a Thing?

What is in a Test?

• Setup everything you need to perform test.Arran

ge

• Call into testable code.

• (Input)

Act• Verify code• (Output)

Assert

Triple "A" Pattern

Page 5: Testing - Is This Even a Thing?

test('Can parse a query string that is passed in', assert => { const reader = new QueryStringReader('?name=bill&home=TN'), pairs = reader.getAttributesAndValues();

equal(pairs[0].name, 'name'); equal(pairs[0].value, 'bill'); equal(pairs[1].name, 'home'); equal(pairs[1].value, 'TN');});

Page 6: Testing - Is This Even a Thing?

test('Clicking buttons changes display', assert => { const s = new SizeChart(analyticsStub, sizingDataStructure); s.display(container);

const cutButtons = container.querySelectorAll('.component-list-picker li'), button = cutButtons[1], contentRegions = container.querySelectorAll('.cut-region'); TestHelper.clickElement(button);

const button1IsSelected = cutButtons[0].classList.contains('selected'), contentRegion1IsShown = contentRegions[0].classList.contains('active'); assert.equal(button1IsSelected, false); assert.equal(contentRegion1IsShown, false);

const button2IsSelected = cutButtons[1].classList.contains('selected'), contentRegion2IsShown = contentRegions[1].classList.contains('active'); assert.equal(button2IsSelected, true); assert.equal(contentRegion2IsShown, true);});

Page 7: Testing - Is This Even a Thing?

What Do I Get Out of Testing?•Confidence in your code.• Being able to refactor your code.• Being able to refactor legacy code.• Testing your code in production!

• What is legacy code?• “To me, legacy code is simply code without tests.” –Michael

Feathers

Page 8: Testing - Is This Even a Thing?

How do I get started?1. Choose a Test Framework• Qunit• Mocha• Jasmine

2. Choose a Test Runner• Karma• Chutzpah• Protractor

3. Start Testing!

Page 9: Testing - Is This Even a Thing?

Final Notes• Test against specific business requirements.

• You shouldn’t be coming up with tests, your stakeholders should!

• Treat tests like production code!

Page 10: Testing - Is This Even a Thing?

Questions?

Page 11: Testing - Is This Even a Thing?

Thank You!

• Nick George <[email protected]>• Sam Schneider <[email protected]>

GTM Networking Night Thursday, November 3rd 4 - 7pm