Ask HN: What's your favorite software testing framework and why?

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • hitchstory

    Type-safe YAML integration tests. Tests that write your docs. Tests that rewrite themselves.

  • If you like pytest and BDD I'd encourage you to check out my library for integration testing: https://github.com/hitchdev/hitchstory

    It's type-safe YAML, plugs into pytest and generates readable, automatically up to date documentation about your app from the test.

  • LazySmallCheck2012

    Lazy SmallCheck with functional values and existentials!

  • I tend to use anything that offers property-testing, since tests are much shorter to write and uncover lots more hidden assumptions.

    My go-to choices per language are:

    - Python: Hypothesis https://hypothesis.readthedocs.io/en/latest (also compatible with PyTest)

    - Scala: ScalaCheck https://scalacheck.org (also compatible with ScalaTest)

    - Javascript/Typescript: JSVerify https://jsverify.github.io

    - Haskell: LazySmallCheck2012 https://github.com/UoYCS-plasma/LazySmallCheck2012/blob/mast...

    - When I wrote PHP (over a decade ago) there was no decent property-based test framework, so I cobbled one together https://github.com/Warbo/php-easycheck

    All of the above use the same basic setup: tests can make universally-quantified statements (e.g. "for all (x: Int), foo(x) == foo(foo(x))"), then the framework checks that statement for a bunch of different inputs.

    Most property-checking frameworks generate data randomly (with more or less sophistication). The Haskell ecosystem is more interesting:

    - QuickCheck was one of the first property-testing frameworks, using random genrators.

    - SmallCheck came later, which enumerates data instead (e.g. testing a Float might use 0, 1, -1, 2, -2, 0.5, -0.5, etc.). That's cute, but QuickCheck tends to exercise more code paths with each input.

    - LazySmallCheck builds up test data on-demand, using Haskell's pervasive laziness. Tests are run with an error as input: if they pass, we're done; if they fail, we're done; if they trigger the error, they're run again with slightly more-defined inputs. For example, if the input is supposed to be a list, we try again with the two forms of list: empty and "cons" (the arguments to cons are both errors, to begin with). This exercises even more code paths for each input.

    - LazySmallCheck2012 is a more versatile "update" to LazySmallCheck; in particular, it's able to generate functions.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • php-easycheck

    Mirror of http://chriswarbo.net/git/php-easycheck

  • I tend to use anything that offers property-testing, since tests are much shorter to write and uncover lots more hidden assumptions.

    My go-to choices per language are:

    - Python: Hypothesis https://hypothesis.readthedocs.io/en/latest (also compatible with PyTest)

    - Scala: ScalaCheck https://scalacheck.org (also compatible with ScalaTest)

    - Javascript/Typescript: JSVerify https://jsverify.github.io

    - Haskell: LazySmallCheck2012 https://github.com/UoYCS-plasma/LazySmallCheck2012/blob/mast...

    - When I wrote PHP (over a decade ago) there was no decent property-based test framework, so I cobbled one together https://github.com/Warbo/php-easycheck

    All of the above use the same basic setup: tests can make universally-quantified statements (e.g. "for all (x: Int), foo(x) == foo(foo(x))"), then the framework checks that statement for a bunch of different inputs.

    Most property-checking frameworks generate data randomly (with more or less sophistication). The Haskell ecosystem is more interesting:

    - QuickCheck was one of the first property-testing frameworks, using random genrators.

    - SmallCheck came later, which enumerates data instead (e.g. testing a Float might use 0, 1, -1, 2, -2, 0.5, -0.5, etc.). That's cute, but QuickCheck tends to exercise more code paths with each input.

    - LazySmallCheck builds up test data on-demand, using Haskell's pervasive laziness. Tests are run with an error as input: if they pass, we're done; if they fail, we're done; if they trigger the error, they're run again with slightly more-defined inputs. For example, if the input is supposed to be a list, we try again with the two forms of list: empty and "cons" (the arguments to cons are both errors, to begin with). This exercises even more code paths for each input.

    - LazySmallCheck2012 is a more versatile "update" to LazySmallCheck; in particular, it's able to generate functions.

  • jsverify

    Write powerful and concise tests. Property-based testing for JavaScript. Like QuickCheck.

  • I tend to use anything that offers property-testing, since tests are much shorter to write and uncover lots more hidden assumptions.

    My go-to choices per language are:

    - Python: Hypothesis https://hypothesis.readthedocs.io/en/latest (also compatible with PyTest)

    - Scala: ScalaCheck https://scalacheck.org (also compatible with ScalaTest)

    - Javascript/Typescript: JSVerify https://jsverify.github.io

    - Haskell: LazySmallCheck2012 https://github.com/UoYCS-plasma/LazySmallCheck2012/blob/mast...

    - When I wrote PHP (over a decade ago) there was no decent property-based test framework, so I cobbled one together https://github.com/Warbo/php-easycheck

    All of the above use the same basic setup: tests can make universally-quantified statements (e.g. "for all (x: Int), foo(x) == foo(foo(x))"), then the framework checks that statement for a bunch of different inputs.

    Most property-checking frameworks generate data randomly (with more or less sophistication). The Haskell ecosystem is more interesting:

    - QuickCheck was one of the first property-testing frameworks, using random genrators.

    - SmallCheck came later, which enumerates data instead (e.g. testing a Float might use 0, 1, -1, 2, -2, 0.5, -0.5, etc.). That's cute, but QuickCheck tends to exercise more code paths with each input.

    - LazySmallCheck builds up test data on-demand, using Haskell's pervasive laziness. Tests are run with an error as input: if they pass, we're done; if they fail, we're done; if they trigger the error, they're run again with slightly more-defined inputs. For example, if the input is supposed to be a list, we try again with the two forms of list: empty and "cons" (the arguments to cons are both errors, to begin with). This exercises even more code paths for each input.

    - LazySmallCheck2012 is a more versatile "update" to LazySmallCheck; in particular, it's able to generate functions.

  • datadriven

    Data-Driven Testing for Go

  • I’ve found the datadriven[1] testing approach in go to be quite effective. The idea is that you leverage a standardized file structure to construct a little DSL for testing your code. This allows you to write expressive tests that print the state of the code and then look at it. Rewrite is also very powerful.

    This is all inspired by the sqllite logic test framework.

    [1]: https://github.com/cockroachdb/datadriven

  • greenlight

    Clojure integration testing framework (by amperity)

  • GitHub: https://github.com/amperity/greenlight

  • ava

    Node.js test runner that lets you develop with confidence 🚀

  • You might want to give ava a spin:

    https://github.com/avajs/ava/

    It has a TAP reporter, but more importantly, as opposed to the more popular solutions, like Jest, the way it achieves parallelism is explained in the docs and won't change anytime soon, thus preventing wonky, hard to debug errors which occur when this part is abstracted away.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • ospec

    Noiseless testing framework

  • ospec is king in JS land. Ultra small, does what I need, gets out of the way and doesn't come with any corny grammar.

    https://github.com/MithrilJS/ospec

  • vitest

    Next generation testing framework powered by Vite.

  • Vitest - https://vitest.dev/ - for JavaScript

    I worked with Jasmine and Jest as well, but Vitest was created recently and to me it seems to have made good improvements over both.

  • Spock

    The Enterprise-ready testing and specification framework.

  • In my opinion it is Spock for Java/Groovy [1]. The amount of functionality and readability you can squeeze from Groovy's DSLesque is absurd. Is basically a full fledged new test language with Java sprinkled as the test contents code

    [1]: https://spockframework.org/

  • embedded-postgres

    Java embedded PostgreSQL component for testing (by zonkyio)

  • Outside of differences between assertion-based unit tests and property-based tests (both of which are worth doing), I don't think framework makes much difference. But your approach to testing definitely does.

    I think every language having its own testing framework is good, even for things like functional tests which can often be externalised. Tests are an essential part of every project and should be well integrated with the rest of the codebase and the team creating it. Often, the tests are the only good place to go and see what an app actually _does_ and so they form an essential part of the documentation.

    In my experience it's very rare that you can effectively create and maintain something like Cucumber tests owned by anyone but the team implementing the code so there's little benefit to translating from a text DSL like that. But the language used is definitely useful, so what I like to see is code in the implementation language that matches the Given/When/Then structure of those tests, but instead of reusable text steps you just have reusable functions which take parameters. This means you can easily refactor, and use the full functionality of your IDE to suggest and go to definitions etc. No matter what, you should treat your test code the same way you do everything else - abstractions matter, so functional tests at the top level should rarely just be about clicking on things and asserting other things, they should be in the language of the domain.

    Functional tests are worth much more than unit tests. No only do they test the only things of actual business value, they are also more robust in the face of implementation refactorings and so require less rework (unless you're being overly specific with CSS selectors etc). Unit tests are often highly coupled to specific implementations and can be a poor investment, especially early in a project. I believe a good balance is functional and integration tests that explore the various paths through your app and prove everything's hooked up, coupled with property based unit tests for gnarly or repetitive logic that isn't worth endlessly iterating via the UI. All other unit tests are optional and at the discretion of the implementer.

    You should be able to mock out every major articulation point in your code, but it's generally preferable if you can mock _real_ dependencies. That is, instead of mocking out a 'repository' abstraction that looks stuff up and returns canned data, have a real test database against which you look up real data (created by steps in your functional tests). This reduces risk and cognitive overhead (you're not having to encode too many assumptions in your test suite) and doesn't have to be as slow as people like to make out - Embedded Postgres is quite fast, for example:

    https://github.com/zonkyio/embedded-postgres

    Same with network services - it's not slow to chat to localhost and you'll find more issues testing proper round-trips. I have not found "assert that you called X" style testing with mocks useful - you care about outcomes, not implementation details.

    Beyond all that, as long as you can make assertions that generate clear error messages, you're fine.

  • tricorder

    Automation the KISS way

  • Thank you. Your library seems nice.

    Unfortunately, I have to say it... I hate YAML with a passion, k8s, github actions/gitlab ci, ansible, etc... When I'm doing ops jobs, I feel like I'm coding in YAML.

    Btw, this hate for YAML birthed https://linkdd.github.io/tricorder/ :P

  • venom

    🐍 Manage and run your integration tests with efficiency - Venom run executors (script, HTTP Request, web, imap, etc... ) and assertions (by ovh)

  • You can also load fixtures in database directly, work with Kafka queues both as a producer (e.g. write an event to a Kafka queue, wait a few seconds and see that it was consumed by the service you test, and that some side effects can be observed) or as a consumer (e.g. make sure after an HTTP call, an event was correctly pushed to a queue), or even read a mailbox in IMAP to check that your service correctly send an email.

    It's a bit rough on the edges sometimes, but I'd never go back on writing integration tests directly in my programming language. Declarative is the way to go.

    [1]: https://github.com/ovh/venom

  • testy

    test helpers for more meaningful, readable, and fluent tests

  • Finished, take a look if you're curious --

    https://github.com/peterldowns/testy

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts