Writing testable code, and how to test it

slides.com/danielsellers/writing-testable-code-and-how-to-test-it/live

What we won't be covering

Test driven development

end to end tests and selenium

the blockchain/ cryptocurrency/bitcoin

Flamethrowers

Flamethrowers

all the testing frameworks and why/when to use each of them

Formal Verification

billions and billions of other things that might have been interesting

What we will be covering

How to write effective unit tests

What the different types of tests are

How to know what type of test to use

Some testing theory

Probably some nerdy cultural references

why test your code?

There are known knowns. These are things we know that we know. There are known unknowns. That is to say, there are things that we know we don't know. But there are also unknown unknowns. There are things we don't know we don't know.

–Donald Rumsfeld

Known Knowns

Code reviews, existing tests

Ensures that the code works and meets the Acceptance Criteria

Known unknowns

existing tests and new Tests


Ensures that we don't break things and that the system keeps working

Unknown Unknowns

Manual Testing, Fuzz testing,  & Formal Verification.
 

Tries to break things. Tries to ensure that code only does what it says

Unknown Unknowns

Easy to test that  code does what it should do. Not easy to test that it only does what it should do.

The pyramid of tests

E2E

Integration

Unit tests

UI

Integration

Unit tests

Let's see some tests!

https://github.com/designfrontier/fib-testing

"TESTS ARE NOT THE PLACE FOR ABSTRACTIONS—THEY ARE THE PLACE FOR CONCRETIONS. ABSTRACTIONS BELONG IN CODE"

​–SANDI METZ

"IF YOU INSIST ON REDUCING DUPLICATION BY ADDING LOGIC TO YOUR TESTS, THIS LOGIC BY NECESSITY MUST MIRROR THE LOGIC IN YOUR CODE..."​

"...THIS BINDS THE TEST TO THE IMPLEMENTATION DETAILS AND MAKES THEM VULNERABLE TO BREAKING EVERY TIME YOU CHANGE THE CODE."​

–Sandi Metz

There are some exceptions to this of course.

Sometimes you using some computer science can simplify your test code.

Let's go take a look real quick

thanks

Made with Slides.com