Slide 1

Slide 1 text

@ivanpaulovich Stockholm, 2020 Oct 20th Testing Strategies Ivan Paulovich

Slide 2

Slide 2 text

@ivanpaulovich

Slide 3

Slide 3 text

@ivanpaulovich What’s TDD? A practice to use tests to guide the software implementation. Boosts the con f i dence to change and to deploy software. Works as a team communication technique.

Slide 4

Slide 4 text

http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd @ivanpaulovich The Rules of TDD 1. You are not allowed to write any production code unless it is to make a failing unit test pass. 2. You are not allowed to write any more of a unit test than is suf f i cient to fail; and compilation failures are failures. 3. You are not allowed to write any more production code than is suf f i cient to pass the one failing unit test.

Slide 5

Slide 5 text

Red-Green-Refactor Red Gren Refactor Write just enough code to pass the test Improve the code without changing its behaviour Write a test and watch it fail TDD Cycle @ivanpaulovich

Slide 6

Slide 6 text

–A regular developer “I technically know what I am allowed to do but I have no clue what I should do.” @ivanpaulovich

Slide 7

Slide 7 text

@ivanpaulovich Testing Pitfalls Rigid tests tight coupled to the modules structure. Slow tests. Repetitive tests. Tests fail due to side effects. Testing the wrong things with the wrong approach.

Slide 8

Slide 8 text

Tests @ivanpaulovich Production Code Software Artifacts Used by customers. Adds value to the product. 
 
 Used by developers. Product value is hidden under “Quality Assurance”.

Slide 9

Slide 9 text

Modular Software Start of the Project Dependencies 
 Added Bugs @ivanpaulovich Big Ball of Mud

Slide 10

Slide 10 text

Services Controllers Repositories Use Cases Domain External APIS Database Single Page Application HTTP TCP HTTP The Typical Software Structure @ivanpaulovich

Slide 11

Slide 11 text

A Wallet Application Deposit Withdraw Transfer Close Account Open Account Database Persistence Exchange Service User Interface Exchange Rates API In Memory SQL In Memory Security @ivanpaulovich

Slide 12

Slide 12 text

A Wallet Application Deposit Withdraw Transfer Close Account Open Account Database Persistence Exchange Service User Interface Exchange Rates API In Memory SQL In Memory Security @ivanpaulovich Testing a Use Case?

Slide 13

Slide 13 text

A Wallet Application Deposit Withdraw Transfer Close Account Open Account Database Persistence Exchange Service User Interface Exchange Rates API In Memory SQL In Memory Security @ivanpaulovich Testing a Dependency?

Slide 14

Slide 14 text

Services Controllers Repositories Use Cases Domain Unit Tets Fake API Fake DB Unit Tests @ivanpaulovich

Slide 15

Slide 15 text

Unit Tests Even though an engineer could write tests for every single class in the project, it is not desirable that tests mimic the software structure. Unit Tests should run fast and in memory. Should not use I/O. Unit Tests are tight coupled to software behaviour. @ivanpaulovich

Slide 16

Slide 16 text

@ivanpaulovich

Slide 17

Slide 17 text

Services Controllers Repositories Use Cases Domain External APIS Database TCP HTTP Integration Tests Integration Tests @ivanpaulovich

Slide 18

Slide 18 text

Integration Tests Integration tests do not mean “test the whole software integrated.” Test each single dependency isolated. It is an expensive solution to test the “database” by calling the “user interface”. @ivanpaulovich

Slide 19

Slide 19 text

@ivanpaulovich

Slide 20

Slide 20 text

Services Controllers Repositories Use Cases Domain External APIS Database Component 
 Tests HTTP TCP HTTP Component Tests @ivanpaulovich

Slide 21

Slide 21 text

Component Tests Tests that check if the modules were wired correctly. Should not make extensive I/O. External dependencies are mocked out. @ivanpaulovich

Slide 22

Slide 22 text

@ivanpaulovich

Slide 23

Slide 23 text

Application External APIS Database End to End 
 Tests HTTP TCP HTTP End to End Tests @ivanpaulovich

Slide 24

Slide 24 text

End to End Tests High usage of I/O. Checks if the real adapters and modules are wired up. Tests should be simpli f i ed for the happy path. Expensive to write and hard to create a variety of cases. @ivanpaulovich

Slide 25

Slide 25 text

@ivanpaulovich

Slide 26

Slide 26 text

What should I test first? Test Kind Criteria Unit Tests Use cases are complicated and requires clari f i cation. Integration Tests Protocols are critical and complex. Component Tests API Contracts needs to be designed and shared. End To End Tests “Never”.

Slide 27

Slide 27 text

Tests Writing Considerations Think about assertion. It should be short. Each test has a single “System Under Test”. Mocks are less valuable than fakes since only fakes could run in production.

Slide 28

Slide 28 text

Common Misconceptions Test-First does not mean “Write the complete test then write the code.” Test-First means “Write a little bit of the test then write a pice of the production code.”

Slide 29

Slide 29 text

Hey engineer, listen to what the tests are saying… @ivanpaulovich

Slide 30

Slide 30 text

1.If test setups are too long. 2.If there are too many assertions. 3.If testing is hard or too slow. Review the code and refactor. @ivanpaulovich