Eric Normand Courses/A06 Beginning Property-Based Testing

Find more bugs faster

14 videos to get you started with the most powerful way to test your code.

  • $99

A06 Beginning Property-Based Testing

  • Closed

Quit writing individual tests and let the computer write thousands of tests for you

Here's a sad fact: even with unit tests, your code can still have bugs.

It turns out that we are bad at writing tests that really exercise the code. Did you find all of the corner cases? Did you test a huge range of inputs?

What if you could enlist the help of your computer to write tests for you, finding more bugs and gaining more confidence in your code?

That's what Property-Based Testing lets you do.

Unfortunately, there haven't been good tutorials on the topic. That's why I created this course.

  • $99

A06 Beginning Property-Based Testing

  • Closed

Clojure's library for Property-Based Testing is called test.check. It's a powerful, full-featured library for getting your computer to write tests for you and finding hard-to-reproduce bugs.

Here's how Property-Based Testing works:
  1. Define the random values the computer will generate—these are called your generators.
  2. Define a boolean expression where true indicates passing, and false indicates failing—this is your property.
  3. Tell the computer how many tests to generate.
test.check will generate random inputs, run them through your code, and see if they pass. It will generate way crazier inputs than you'd ever think to generate, and as many as you ask for. This is why test.check can find bugs that you would have missed.

However, it's not done there. Seeing a crazy, random value that happens to fail is not helpful. Why did it fail? What, in particular, is wrong with it? That's where the magic happens. test.check will figure out a minimum failing value—through a process called shrinkage—that is so small and clear that you can know very easily why it failed. Shrinkage is one of the keys to making Property-Based Testing work for you.

What you will learn in this course

Property-Based Testing is a powerful technique and there's a lot to learn. This beginner's introduction to the topic will give you everything you need to get started.

  • How to use built-in generators and how to build your own
  • 3 strategies for defining properties so you'll never get stuck
  • Testing before you implement, like in TDD
  • Testing after you implement, which is only possible with property-based testing
And, of course, plenty of examples for each of them. You'll also get an in-depth understanding of how the whole process works.

In this course, you will be watching me test code. You'll see how I read error messages and get out of trouble. You'll see how I develop the tests interactively using the REPL. You'll see how to use the REPL to better understand your generators and properties.

  • $99

A06 Beginning Property-Based Testing

  • Closed

Contents

What is Property-Based Testing?
What is test.check?
Advantages of Property-Based Testing
When can you use Property-Based Testing?
How does Property-Based Testing work?
An overview of property-based testing with an example test
A tour of the built-in generators
Building your own simple generators
Strategies for properties: functionality
Strategies for properties: invariants
Strategies for properties: algebraic properties
Testing pure functions
When to test: before implementation
When to test: after implementation

  • $99

A06 Beginning Property-Based Testing

  • Closed