Slide 1

Slide 1 text

Flutter Test Pyramid Sayeed & Chandru

Slide 2

Slide 2 text

Ground Rules Feel free to stop us if you don’t understand something Let’s keep it interactive No question is silly

Slide 3

Slide 3 text

Q. What is a test in developer terminology

Slide 4

Slide 4 text

A Some code to AUTOMATICALLY validate some other code

Slide 5

Slide 5 text

Different kinds of tests Unit Tests UI Tests Integration Tests Functional Tests Snapshot Tests * Contract Tests * Performance Tests

Slide 6

Slide 6 text

Comparison of Various Types Of Tests Speed Feedback Cycle Confidence Flakiness/Dep endencies Cost of Maintenance Unit Fast Fast Low Low Low Integration Fast Fast Medium Medium Medium Functional Slow Slow High High High

Slide 7

Slide 7 text

Principles of Test Distribution Based on the trade-offs, an ideal test distribution should optimize for * Maximum Unit tests * Sufficient Functional tests to cover important app flows Required number integration tests When we do this, the shape of test distribution generally turns out to be a PYRAMID

Slide 8

Slide 8 text

Q. What is a test pyramid

Slide 9

Slide 9 text

A. Way to distribute different kinds of tests

Slide 10

Slide 10 text

Test Distribution Anti-Patterns

Slide 11

Slide 11 text

Agenda How to distribute tests for a Flutter app across different layers of tests

Slide 12

Slide 12 text

Before We Dive Into Code Let’s understand the importance of App Architecture in achieving test pyramid

Slide 13

Slide 13 text

Application Architecture & Test Pyramid Layering your app correctly using SOLID principles makes achieving the right test pyramid

Slide 14

Slide 14 text

Common Architecture Anti-patterns - Difficulty In Testing Logic code in UI classes UI classes hard & slow to test Lack Of Dependency Injection - We end up integration testing instead of unit - Test setup becomes difficult

Slide 15

Slide 15 text

Sample App Architecture - Single Responsibility Principle - Dependency Inversion - bLoc pattern with Reactive State Management - Dependency Injection - Clean Architecture Layers - data, domain, presentation

Slide 16

Slide 16 text

HandsOn What to test, Which layer of test pyramid to test it in

Slide 17

Slide 17 text

Q. What all do we need to test in the product list screen -

Slide 18

Slide 18 text

A.

Slide 19

Slide 19 text

Sample App Architecture Walkthrough

Slide 20

Slide 20 text

Unit Tests

Slide 21

Slide 21 text

Widget Tests - ProductListTest - What to test [branch widget_test_1] - ProductListItemTest - What to test [branch widget_test2] - ProductListScreenTest - What to test [branch widget_test3]

Slide 22

Slide 22 text

Integration Tests Actually they are Functional Tests - They require a real device to run on - They are much slower - Multiple tests in a _test file depend on each other in terms previous state - Hard to change application setup from test file - Hard to debug failing test. Error messages not descriptive enough

Slide 23

Slide 23 text

Golden File Tests Q. When to use Golden File Tests A. Keep it minimal. Test only critical functionality where alignment/size of UI controls could be a make or break scenario. a. [Should Test] Add To Cart button size as without this you get no money b. [Should Not Test] Profile page - They can be flaky as even 1px misalignment causes failure - Need to maintain golden images in CI which can increase repo size [branch golden_test_1]

Slide 24

Slide 24 text

References Talk to Us On Gitter -> https://gitter.im/gdg-flutter-test-pyramid/community See The Code Here -> https://github.com/sayeedhussain/flutter_test_pyramid_gdg Thank You