Property Testing in Elm

Elm is perfectly suited to property testing, with its delightful data-in–data-out functions. Testing in Elm should super easy. The tooling isn’t there yet, though. This post documents what was necessary today to get a property to run in Elm. Step 1: elm-test This includes an Elm library and a node module for a command-line runner. The library … Read moreProperty Testing in Elm

Ultratestable Coding Style

Darn side-effecting programs. Programs that change things in the outside world are so darn useful, and such a pain to test.For every piece of code, there is another piece of code that answers the question, “How do I know that code works?” Sometimes that’s more work than the code itself — but there is hope. … Read moreUltratestable Coding Style

Property tests don’t have to be generative

Now and then, a property test can be easier than an example test. Today, Tanya and I benefited. There’s this web service. It returns a whole tree of information, some of it useful and some of it is not. { “category”: “food”,  “children: [ { “category” : “fruit”,                … Read moreProperty tests don’t have to be generative

TDD with generative testing: an example in Ruby

Say I’m in retail, and the marketing team has an app that helps them evaluate the sales of various items. I’m working on a web service that, given an item, tells them how many purchases were influenced by various advertising channels: the mobile app, web ads, and spam email. The service will look up item … Read moreTDD with generative testing: an example in Ruby

TDD is Dead! Long Live TDD!

Imagine that you’re writing a web service. It is implemented with a bunch of classes. Pretend this circle represents your service, and the shapes inside it are classes. The way I learned test-driven development[1], we wrote itty-bitty tests around every itty-bitty method in each class. Then maybe a few acceptance tests around the outside. This … Read moreTDD is Dead! Long Live TDD!

Quick reference: monads and test.check generators

Combine monads with test.check generators to build them up out of smaller generators with dependencies: (require ‘[clojure.test.check.generators :as gen])(require ‘[clojure.algo.monads :as m])(m/defmonad gen-m   [m-bind gen/bind    m-result gen/return]) (def vector-and-elem  (m/domonad gen-m    [n (gen/choose 1 10)     v (gen/vector gen/int n)     e (gen/element v)]    [v, e])) (gen/sample vector-and-elem);; ([[0 0] 0]     [[0 -1 1 0 -1 0 -1 1] 0]   … Read moreQuick reference: monads and test.check generators

Testing akka actor termination

When testing akka code, I want to make sure a particular actor gets shut down within a time limit. I used to do it like this:  Thread.sleep(2.seconds) assertTrue(actorRef.isTerminated()) That isTerminated method is deprecated since Akka 2.2, and good thing too, since my test was wasting everyone’s time. Today I’m doing this instead: import akka.testkit.TestProbeval probe = … Read moreTesting akka actor termination

Property-based testing of higher-order functions

Property-based testing and functional programming are friends, because they’re both motivated by Reasoning About Code. Functional programming is about keeping your functions data-in, data-out so that you can reason about them. Property-based testing is about expressing the conclusions of that reasoning as properties, then showing that they’re (probably) true by testing them with hundreds of … Read moreProperty-based testing of higher-order functions