Slide 1

Slide 1 text

Jakob Mattsson @jakobmattsson Developer • Entrepreneur • Crazy person

Slide 2

Slide 2 text

2 000 000 000 writes/day!

Slide 3

Slide 3 text

Quick and easy customer feedback. touch-and-tell.se

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Automated CSS Testing Not Just a Myth

Slide 10

Slide 10 text

The purpose of this presentation: Raise awareness of existing tools Inspire a new workflow Get your help

Slide 11

Slide 11 text

The purpose of this presentation: Raise awareness of existing tools Inspire a new workflow Get your help

Slide 12

Slide 12 text

The purpose of this presentation: Raise awareness of existing tools Inspire a new workflow Get your help

Slide 13

Slide 13 text

The purpose of this presentation: Raise awareness of existing tools Inspire a new workflow Get your help

Slide 14

Slide 14 text

Declarative programming

Slide 15

Slide 15 text

Declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow.” “

Slide 16

Slide 16 text

Do not try it @127.0.0.1

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Mixins Variables Reuse Nesting etc. Operations

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Write Read

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

New styles are added instead of reuse

Slide 26

Slide 26 text

New styles are added instead of reuse Unused styles are not removed

Slide 27

Slide 27 text

New styles are added instead of reuse Unused styles are not removed No overview of how different styles interact

Slide 28

Slide 28 text

New styles are added instead of reuse Unused styles are not removed No overview of how different styles interact Form factors, adaptiveness, responsiveness

Slide 29

Slide 29 text

New styles are added instead of reuse Unused styles are not removed No overview of how different styles interact Form factors, adaptiveness, responsiveness The true ”write-only” language

Slide 30

Slide 30 text

In computer humor, a write-only language is a programming language with syntax (or semantics) sufficiently dense and bizarre that any routine of significant size is too difficult to understand by other programmers and cannot be safely edited.” “

Slide 31

Slide 31 text

Code quality

Slide 32

Slide 32 text

Functional quality—fitness for purpose Structural quality—the degree to which the so!ware was produced correctly

Slide 33

Slide 33 text

Structural quality Reliability Maintainability Size Efficiency Security

Slide 34

Slide 34 text

HOW?

Slide 35

Slide 35 text

By writing automated TESTS!

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

Refactor Red Green 1.Write a test that fails 2.Make the code work 3.Eliminate redundancy

Slide 38

Slide 38 text

Testing CSS

Slide 39

Slide 39 text

Code ??? Profit Declarative Dilemma

Slide 40

Slide 40 text

Let’s try!

Slide 41

Slide 41 text

1 2 3 4 Two for code Two for result { { Four approaches

Slide 42

Slide 42 text

1

Slide 43

Slide 43 text

Syntax Checks Checking that the code is actually valid CSS Typically performed by an editor, IDE or plugin

Slide 44

Slide 44 text

2

Slide 45

Slide 45 text

Styleguides & linting Forces best-practices to be followed Syntactically (where to put braces) Semantically (catching common mistakes)

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

Useless without good rules + - Prevents anti-patterns Easy to apply Doesn’t test the end result - - +

Slide 48

Slide 48 text

3

Slide 49

Slide 49 text

Screenshots Compare visuals before and a"er change Detects impact of change

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

Lots of false positives + - No change can sneak by Implementation agnostic Breaks on content changes - - +

Slide 52

Slide 52 text

4

Slide 53

Slide 53 text

Comparing styles in the DOM Sniff the DOM for all relevant styles Compare them to some expectation

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Scenario: Standard paragraph color Given I visit "http://localhost:3000" Then "section > p" should have "color" of "rgb(68, 68, 68)"

Slide 56

Slide 56 text

Style rules != looks + - Resilient to changes Tests live on Writing expectations in code - - +

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

WHAT is the MISSING PIECE?

Slide 61

Slide 61 text

Design first

Slide 62

Slide 62 text

Refactor Red Green 1.Write a test that fails 2.Make the code work 3.Eliminate redundancy

Slide 63

Slide 63 text

My suggestion: 1. Create the design you want 2. Ensure consistency and compatibility 3. Eliminate redundancy

Slide 64

Slide 64 text

My suggestion: 1. Create the design you want 2. Ensure consistency and compatibility 3. Eliminate redundancy

Slide 65

Slide 65 text

My suggestion: 1. Create the design you want 2. Ensure consistency and compatibility 3. Eliminate redundancy

Slide 66

Slide 66 text

My suggestion: 1. Create the design you want 2. Ensure consistency and compatibility 3. Eliminate redundancy

Slide 67

Slide 67 text

Refactor Red Green 1.Create the design you want 2.Ensure consistency and compatibility 3.Eliminate redundancy

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

Click

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

Examples

Slide 72

Slide 72 text

ul:last-child { color: red; } Won’t work in IE8. Will be caught when test runs there. #footer { width: calc(100% - 3em); } Won’t work on Android or Safari < 6 Unsupported CSS-style used

Slide 73

Slide 73 text

CSS-inconsistency across browsers h1, h2, h3, h4, h5, h6, a { display: block; } ul { list-style-position: inside; }
  • Foobar

    • Chrome Firefox

Slide 74

Slide 74 text

body { margin:0; padding:0; } div { margin:0; padding:10; }
Foobar
body { margin:10; padding:0; } div { margin:0; padding:0; }
Foobar
Detecting equivalent styles This change does not trigger an error; the rendered result is the same, even though styles differ.

Slide 75

Slide 75 text

Now what?

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Join in!

Slide 78

Slide 78 text

Automated CSS Testing Not Just a Myth @jakobmattsson • [email protected] github.com/leanmachine/testbit

Slide 79

Slide 79 text

Automated CSS Testing Not Just a Myth @jakobmattsson • [email protected] github.com/leanmachine/testbit bit.ly/jakob-mmwcon + -