Lets Talk About Tests

A 'back to basics' walk through of testing methodologies

Justin Herrick

Software Developer

Consultant

Educator

 

Quiz Time

Buzzwords

  • TDD
  • BDD
  • SOLID
  • DIC
  • CI
  • Robustness
  • Fragility
  • Coupling
  • Cohesion
  • Code Coverage
  • Cyclomatic Complexity
  • RGR
  • Integration Tests
  • Unit Tests
  • Acceptance Tests
  • Mocks
  • Stubs
  • Spies
  • Generative Testing
  • Referential Transparency
  • Test to Code Ratio
  • Test Case vs Spec
  • xUnit vs Spec
  • Chicago vs London
  • State vs Functional
  • Mocking Libs vs Hand Rolled
  • Outside In vs Inside Out
  • etc...

Research

Why do we write tests?

Writing working software is hard

Understanding someone else's code is hard

Responding to change is hard

What are the benefits of testing?

Makes writing working software easier

Helps in understanding the code of others

Makes responding to change easier

 

Since testing solves all our problems, we test everything, without fail.

Why are we not all TDDing all the time?

 

Why do people dislike tests?

Makes writing working software harder

Understanding the tests of others is hard

Makes responding to change harder

Wait

I thought tests fixed these issues?

Tests are not a magic bullet

Tests will not fix

Your code base

Your process

Your co-worker

(Yah that one)

Tests are still awesome even without the magic

Back To The Basics

 

Testing is Good Because

  • Save you time on repetitive tasks
  • Works as a secondary form of documentation
  • Allow you to deliver features and make changes with confidence

If your tests do not provide you with at least 2 of those benefits then I would question their effectiveness

"Tests allow us to respond to change faster and allow us to produce code with less bugs"

*

*

*

*

*

*

Caveats

Assumes you are writing good tests.

Less bugs is a hard number to quantify in any given project.

Easier to respond to change is super subjective.

Its okay

We just need to write good tests

A good test needs to be well thought out.

A good test needs to know what it is testing and what it is not testing

 

A good test should have a goal in mind

What do I test?

Test your application/business logic

Test methods and classes that have state and logic.

Test error prone or complicated systems

Test "mission critical" systems

Test as you go

What do I not test?

Do not test your framework

Do not test your language

Don't test your UI*

Do not test 3rd party libraries or services

 

Don't test your mocks

Types of (Unit) Tests

State Based

Did x occur when I did y

Return Value

Did I get x back when I did y

Avoid testing things that are fundamentally hard to test.

What is hard to test?

Loops

Randomness

UI / Output

State

When do I know my tests are good enough?

Tests are about feeling confident in your code.

Readability is of utmost importance in your test suite

You need to be proactive about refactoring and maintaining your tests

Conclusion

Testing is Hard

With good tests we can write better code

Writing good tests requires practice

Writing good tests requires remembering the basics

Thank You

Q&A?

Made with Slides.com