Slide 1

Slide 1 text

AUTOMATION TESTING LEGACY APPLICATIONS @EmanuilSlavov OF

Slide 2

Slide 2 text

Your application is legacy, if you don’t have automated tests.

Slide 3

Slide 3 text

GREENFIELD PROJECT

Slide 4

Slide 4 text

BROWNFIELD PROJECT BROWNFIELD PROJECT

Slide 5

Slide 5 text

WHY INVEST IN LEGACY SYSTEM? TEAM HAPPINESS

Slide 6

Slide 6 text

LOW TEAM MORALE

Slide 7

Slide 7 text

Fragile Software Slow Feedback Stupid Errors Repetitive Work

Slide 8

Slide 8 text

Quality software is team effort.

Slide 9

Slide 9 text

SHIFT LEFT

Slide 10

Slide 10 text

WHAT TO DO ABOUT IT

Slide 11

Slide 11 text

Start with basic acceptance tests

Slide 12

Slide 12 text

Functionality that makes money Must have functionality - compliance, security Repeating Manual Tests - Save Time Pareto Principle - 80/20

Slide 13

Slide 13 text

Do not test through the UI. (if possible)

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

result = RestClient.post( REGISTER_URL, user_details.to_json, {:content_type => :json} )

Slide 16

Slide 16 text

800 test x 10 seconds = 2h 13min This saved us:

Slide 17

Slide 17 text

Limit external dependencies calls.

Slide 18

Slide 18 text

Need to Call External System Comes from automated test? Talk to the real system No Fake the response Yes

Slide 19

Slide 19 text

Test should create the data they need.

Slide 20

Slide 20 text

Scenario: Client admin should not be able to view master’s agencies Given а master user And master creates agency And a client admin When client admin views master's agency Then client admin should get an error

Slide 21

Slide 21 text

Set test data via API or DB.

Slide 22

Slide 22 text

Poll for results from API/DB operations.

Slide 23

Slide 23 text

sleeping(1).seconds.between_tries.failing_after(10).tries do result = some_operation raise 'No Data' if result == [] end

Slide 24

Slide 24 text

Run a test 20 times consecutively. Commit only if the test does not fail.

Slide 25

Slide 25 text

for i in {1..20}; do your_test; done

Slide 26

Slide 26 text

Make async tasks sync

Slide 27

Slide 27 text

CODE CHANGES

Slide 28

Slide 28 text

First Order of Business: Remove Unused Code

Slide 29

Slide 29 text

KNIGHT CAPITAL MELTDOWN LOST $440 MILLION IN 45 MINUTES

Slide 30

Slide 30 text

Second Order of Business: Stop The Rot

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

CONTINUOUS INTEGRATION

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

Run on every commit Fast Hook one by one all the checks Run longer tests periodically

Slide 35

Slide 35 text

Developers need to receive feedback about their new code within 5 minutes.

Slide 36

Slide 36 text

WHAT CHECKS TO RUN ON COMMIT?

Slide 37

Slide 37 text

The PHP Case

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

php -l api/models/mobile_push_model.php PHP Parse error: api/models/mobile_push_model.php on line 61 Errors parsing api/models/mobile_push_model.php Linter

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

UnknownObjectMethod in file: api/models/mobile_push_model.php, line: 55, problem entry: $pusher->reallyUnsubscribeDevice ($params['user_id'], $params['device_id'], $actions) HHVM

Slide 42

Slide 42 text

STATIC CODE QUALITY

Slide 43

Slide 43 text

CYCLOMATIC COMPLEXITY function testPrint() { echo('Hello World'); } Complexity: 1 function testPrint($parameter) { if($parameter) { echo('Hello World'); } } Complexity: 2

Slide 44

Slide 44 text

Method complexity should be less than 10.

Slide 45

Slide 45 text

12 Fatalities $1,2 Billion Settlement

Slide 46

Slide 46 text

”The throttle angle function scored [complexity] over 100 (unmaintainable)” Michael Barr

Slide 47

Slide 47 text

Complexity 82 Complexity 10 Constantly refactor to decrease complexity

Slide 48

Slide 48 text

Method size should be less than 100 lines (ideally less than 50).

Slide 49

Slide 49 text

Improve the code - then lower the threshold on commit check. Then repeat.

Slide 50

Slide 50 text

FIGHT LEGACY CODE WRITE UNIT TESTS

Slide 51

Slide 51 text

Written by Developers Fast, Independent Test Technical Aspects Cooperation between QA & Developers

Slide 52

Slide 52 text

[Demo]

Slide 53

Slide 53 text

100% test coverage is not sufficient!

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

SECURITY TESTS

Slide 56

Slide 56 text

SQL Injection Detection (PHP and ADOdb) $dbConn->GetRow(“SELECT * FROM users WHERE id = $user_id”) $dbConn->GetRow(“SELECT * FROM users WHERE id = ?”, array(‘$user_id’))

Slide 57

Slide 57 text

Those errors can be caught with code analysis.

Slide 58

Slide 58 text

There was no such tool. So we developed one.

Slide 59

Slide 59 text

github.com/emanuil/php-reaper

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

MONITORING

Slide 62

Slide 62 text

Your second line of defense.

Slide 63

Slide 63 text

Show a lot with TV and Raspberry Pi.

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Live Graphs + Deploys

Slide 66

Slide 66 text

CONCLUSION

Slide 67

Slide 67 text

Аutomatе the most important functionalities Continuously improve static code quality Write unit tests for changed/new code Expand checks on commit Enable monitoring

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

@EmanuilSlavov EmanuilSlavov.com