Genything – Generate Anything

Genything is a framework for random testing of a program properties. It provides way to random data based on simple and complex types.

Combined with Trickery it allows the generation of data according to real world scenarios, which can be used for code testing, demo applications, ui testing, usability tests, be creative!

About

An opinionated distillation of the successful patterns from QuickCheck, SwiftCheck, and Kotest.
Directed towards testing of a product rather than library.

Why use Genything?

  • We do not depend on XCTest
  • Predictable randomness is expected
  • We are agnostic to how the generators are used
    • Testing scenarios that require pseudo-random data
    • Realistic models for previewing content and detecting UI issues

Arbitrary Types

Arbitrary types provide a pseudo-random generator suitable for checking the hypothetical correctness of code without strict definition of all cases. It’s used for property testing.

Trickery

Genything comes together with Trickery, a collection of generators suitable for producing pseudo-realistic data according to real-world-conditions rather than those enforced only by the type.

Consider a phone number. A phone number of type String has rules about length, formatting, allowable characters. Whereas the arbitrary type String contains contains at most a definition of it’s length

Features

Genything

  • Linear Congruential Generator
  • Arbitrary of: Bool, Double, Int, UInt, Int32, UInt32, UnicodeScalar, Character, String, Array, Optional, AnySequence, AnyBidirectionalCollection, ArraySlice, Dictionary, CGFloat, UUID, Core Location

Trickery

  • Fake of: Characters, ID, Locattion, Lorem, Numerics, Web, Person, Address, Telephone
  • Can create fake from json using Codable

Usage

Genything/Gen

Will print one of the cities from the generator

import Genything

let genCities = Gen.of(["Winnipeg","Calgary","Vancouver","Halifax"])
debugPrint(genCities.sample())

Genything/Arbitrary

Will print an arbitrary string with any number of random characters

import Genything
 
let arbitraryString = String.arbitrary.sample()
debugPring(arbitraryString)

Trickery/Fake

Will print a random alphanumeric character

import Trickery

let fakeAlphanumericCharacters = Fake.Characters.alphanumeric.sample()
debugPrint(fakeAlphanumericCharacters)

Installation

Cocoapods

pod 'Genything'
pod 'Trickery'

Swift Package Manager

Create a Package.swift file in your root directory and add:

dependencies: [
    .package(url: "https://github.com/justeattakeaway/genything.git", .exact("0.0.1"))
]

Credits

The Genything and Trickery projects are owned and maintained by SkipTheDishes, a Just Eat Takeaway subsidiary.

Contributing

Please read the Contribution Guide

Inspiration

License

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/

GitHub

View Github