Generating test cases with SwiftCheck

updated over 1 year ago; latest suggestion over 1 year ago


Writing unit tests is one of the most important parts of producing software. Tests prove correctness of your program, they help catch bugs early in development cycle, they guard against regressions, and may even act as documentation.

Having such high expectations, it is very important that your unit tests actually meet them and that your test cases cover more than just one happy path. Although coming up with various test cases, especially with erroneous ones, might be hard, there is a solution for that problem.

In my talk, I will introduce you to an alternative approach of property-based testing using SwiftCheck and the idea of having tests find edge cases for you.


  1. Introduction
  2. Traditional ways of writing test cases
    1. Overview
    2. Describing the problem
  3. Introduction to SwiftCheck
    1. Idea of property-based testing
    2. Brief history of SwiftCheck
    3. Fundamental principles and features of SwiftCheck
  4. Using SwiftCheck
    1. Testing pure functions and algorithms
    2. Testing stateful code
    3. Extending SwiftCheck
      1. Supporting custom types
      2. Composing generators
      3. Custom generators
    4. Replaying tests
    5. Integrating with Quick and Nimble
  5. Summary


  • The proposal author responds over 1 year ago

    Thanks for the suggestion! Yes, comparison to standard ways of testing and real-life examples are part of section 4. In addition, I would like to describe how to take advantage of both worlds to make tests reliable and more helpful.

  • 4026dcb26d5a41a2630b9f4bdbb294c6bfebf026?size=100x100 4026dcb26d5a41a2630b9f4bdbb294c6bfebf026 suggests over 1 year ago

    An interesting topic, I would love to learn how to improve testing. It would be awesome to put a special emphasis on highlighting the differences between a standard way of writing unit tests and using SwiftCheck with some examples. That will help to convince business people not only to do unit tests in projects but also to do it right.

  • The proposal author responds over 1 year ago

    Thanks for the suggestions! I updated the proposal accordingly.

  • 7ca58a9839f41070cefa481ae43fbc1225f16a4e?size=100x100 7ca58a9839f41070cefa481ae43fbc1225f16a4e suggests over 1 year ago

    I once saw short presentation about SwiftCheck. It's not that kind of framework that you install and are ready to use, some introduction is need. So I think it's interesting to hear about it more and section 3 from agenda is a good idea!

  • 4a0b4e68bfadfd7cf98b900651d625b771c5b51f?size=100x100 4a0b4e68bfadfd7cf98b900651d625b771c5b51f suggests over 1 year ago

    SwiftCheck is a great tool. I'm looking forward to hearing more advanced topics. I hope you could present more than one example of custom generators.

  • 2db9b26eaada363a9cd80221d10fe692aea08f19?size=100x100 2db9b26eaada363a9cd80221d10fe692aea08f19 suggests over 1 year ago

    Sounds interesting! I would skip the overview of "traditional" unit tests and go straight to the problems. I also hope you will say more on how test data generation can be implemented for custom types in section 4.3.