Test automation expert days

47
Test Automation Oren Rubin - Testim.io

Transcript of Test automation expert days

Test AutomationOren Rubin - Testim.io

Who am I?

Who are you?

● Company specialty?

o Backend? Frontend? Mobile?

● Current development?

o how frequent are the releases?

● QA or dev team?

o Write code or manage?

Software Architecture Class

Q: How to write large scale applications?

A: You don't, you aim for small reusable

components

Systems are composed of Units

Unit A Unit B Unit C

Units have interfaces

Browser Web Server DBClick HTTP

Units are composed of smaller units

Web

ServerDB

Click

Browser

HTML

JS

CSS

a.js b.js

Test each unit separately?

Browser Web Server DB

Test A Test B Test C

Test how the units interact?

Browser Web Server

Test A

DB

Test how the units interact?

Web Server DB

Test C

Browser

Test the entire flow?

Browser Web Server DBClick HTTP

Testing Theory - La järɡən

● Unit Tests

● Integration Tests

● End to End Tests

● Functional Tests

● Smoke Tests

● Load Tests

● Acceptance Test

Testing Theory - La järɡən

Unit vs. Integration vs. E2E

Testing Theory

The Assertions can differ:

Functional, UI, Timing, Memory consumption

Test starts Initial State Some StateSetup Stimuli Assertions Tear down

Testing Theory

Black Box

● Check against the API

● Can be done by others

White Box

● Look inside (gory details)

● Usually same person

Testing Metrics

Black Box

● Users stories

● Response time

● Memory consumption

(memory leaks)

White Box

● Code coverage

● Loop edge cases:

o Never go in

o Go in once

o More than once

Test automation

Unit Tests

Unit Tests.. find the diffs

Bad Code

● Long methods

● Tightly Coupled

● Unreadable

● Hard root cause

● Use Global

Good Code

● Short methods

● Loose Coupling

● Readable

● Easy bug detection

● Separation of

Concerns

Unit Tested Code

● Short methods

● Loose Coupling

● Readable

● Easy bug detection

● Separation of

Concerns

Unit Tests

Remember:

Units tests helps you write better code

Regression tests are a bonus!

Testing Theory - Unit Tests

Assertions

● State changed

● callbacks (methods) were called

Test starts Initial State Some StateSetup Stimuli Assertions Tear down

Testing Theory - Unit Tests

Assertions

● State changed

● callbacks (methods) were called

Test starts Initial State Some Statea =new A() a.f() assert(a.x = 5)

Test each unit separately?

Browser Web Server DB

Test A Test B Test C

mock http

mock timers

Unit Isolation

Spies

Stubs

Mocks

Unit Isolation - if needed

Fake ajax

Fake timers

Work asynchronously

Assertion Library

Spies

Spy on functions

Spy on functions

Spy on functions

Spy filters

Spy Assertions

Spy Assertions

Stubs

Stubs

Stubs

Mocks

Jasmine

● Very simple

● Great docs: http://pivotal.github.com/jasmine/

● Load is by an HTML scaffold

● Completely standalone

● Custom Matchers: expect('moshe').toBeMoshe();

● Easy to filter tests

● Nested describe blocks (each has beforeEach)

Jasmine

Jasmine

Jasmine

Sinon

Asynchronous - Jasmine

Jasmine async riddle

TDD

1. Write test

2. Test fails

3. Write code

4. Test passes

5. Refactor

6. Go to 2

Keyword driven tests e.g. cucumber

TDD can apply to Integration and E2E