ITB2016 - Integration testing in a modern world

26
INTEGRATION TESTING IN A MODERN WORLD

Transcript of ITB2016 - Integration testing in a modern world

Page 1: ITB2016 - Integration testing in a modern world

INTEGRATION TESTING IN A

MODERN WORLD

Page 2: ITB2016 - Integration testing in a modern world

WHAT THIS TALK ISN'T!

> Framework Agnostic> A strict TDD regiment> How to do Unit testing

Page 3: ITB2016 - Integration testing in a modern world

WHAT THIS TALK IS!

> Practical Testing> Ways to test against the Database

> An awesome new way to assert against your responses

Page 4: ITB2016 - Integration testing in a modern world

OTHER SESSION RIGHT NOW

> Web Applications Can Control The WorldBox Room

Page 5: ITB2016 - Integration testing in a modern world

WHO AM I?

ERIC PETERSON

> ! Utah

> " O.C. Tanner

> # 1 wife, 1 kid

Page 6: ITB2016 - Integration testing in a modern world

SO YOU WANT TO START TESTING....!

Page 7: ITB2016 - Integration testing in a modern world

UNIT TESTING

Page 8: ITB2016 - Integration testing in a modern world

Works really well on individual components.it('calculates the square root', function() { var CUT = new Calculator(); expect(CUT.sqrt(25)).toBe(5);});

!

Page 9: ITB2016 - Integration testing in a modern world

...not as well when you have collaborator components.it('renders the welcome view', function() { var CUT = getMockBox() .createMock('handlers.Welcome'); var mockService = getMockBox().createMock('models.WelcomeService'); mockService.$('getGreeting', 'Greetings!'); CUT.mockProperty(propertyName = 'service', mock = mockService); var event = CUT.index(); expect(event.getValue('greeting')).toBe('Greetings!');});

!

Page 10: ITB2016 - Integration testing in a modern world

Here's the same test as an Integration test.it('renders the welcome view', function() { var event = execute(event = 'Welcome.index', renderResults = true);

expect(event.getValue('greeting')).toBe('Greetings!');});

!

Page 11: ITB2016 - Integration testing in a modern world

Before we go any further...

PROS AND CONS

Page 12: ITB2016 - Integration testing in a modern world

PROS

> Easier to get started with> Makes sure that your application is wired together

correctly> Avoids Mocks (which can be really confusing)

> High level tests make refactoring easier

Page 13: ITB2016 - Integration testing in a modern world

CONS

> Slow> Doesn't really help you do TDD

> Really slow> Needs a testing database of some kind

> Did I mention slow?

Page 14: ITB2016 - Integration testing in a modern world

IN REALITY?

Page 15: ITB2016 - Integration testing in a modern world

DEMOTHE APP

Page 16: ITB2016 - Integration testing in a modern world

DEMOA SIMPLE INTEGRATION TEST

Page 17: ITB2016 - Integration testing in a modern world

PROBLEM

Running the test multiple times fails or creates multiple database records

Page 18: ITB2016 - Integration testing in a modern world

DEMOA TESTING DATABASE

Page 19: ITB2016 - Integration testing in a modern world

PROBLEM

If we want to use database transactions, we can only make one request

Also, the tests are getting kind of messy

Page 20: ITB2016 - Integration testing in a modern world

INTEGRATEDHTTPS://GITHUB.COM/ELPETE/INTEGRATED

Page 21: ITB2016 - Integration testing in a modern world

WHAT IS INTEGRATED?

> Built on ColdBox (4.2+) and TestBox (2.3+)> Augments the built-in ColdBox Integration test

> Easy database transactions across multiple requests> jQuery-style page assertions

Page 22: ITB2016 - Integration testing in a modern world

WHAT IS INTEGRATED?

it('renders the welcome view', function() { this.visit('/') .see('Greetings!');});

!

Page 23: ITB2016 - Integration testing in a modern world

WHAT IS INTEGRATED?

it('renders the welcome view', function() { this.visit('/dashboard') .seePageIs('/login') .click('Register') .type('John', 'username') .type('[email protected]', 'email') .type('mY@wes0meP@ssw0rd', 'password') .press('Submit') .seePageIs('/dashboard') .see('Welcome to the team, John!');});

!

Page 24: ITB2016 - Integration testing in a modern world

DEMOINTEGRATED

Page 25: ITB2016 - Integration testing in a modern world

OTHER SESSIONS AT DEV.OBJECTIVE()

CFML Sessions for DummiesWednesday

3:00 PM to 4:00 PM

Live Testing a Legacy AppThursday

1:45 PM to 2:45 PM

Page 26: ITB2016 - Integration testing in a modern world

THANK YOU!!

elpete

@_elpete

! dev.elpete.com