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!
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 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.
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
- Linear Congruential Generator
- Arbitrary of: Bool, Double, Int, UInt, Int32, UInt32, UnicodeScalar, Character, String, Array, Optional, AnySequence, AnyBidirectionalCollection, ArraySlice, Dictionary, CGFloat, UUID, Core Location
- Fake of: Characters, ID, Locattion, Lorem, Numerics, Web, Person, Address, Telephone
- Can create fake from json using Codable
Will print one of the cities from the generator
import Genything let genCities = Gen.of(["Winnipeg","Calgary","Vancouver","Halifax"]) debugPrint(genCities.sample())
Will print an arbitrary string with any number of random characters
import Genything let arbitraryString = String.arbitrary.sample() debugPring(arbitraryString)
Will print a random alphanumeric character
import Trickery let fakeAlphanumericCharacters = Fake.Characters.alphanumeric.sample() debugPrint(fakeAlphanumericCharacters)
pod 'Genything' pod 'Trickery'
Swift Package Manager
Package.swift file in your root directory and add:
dependencies: [ .package(url: "https://github.com/justeattakeaway/genything.git", .exact("0.0.1")) ]
Please read the Contribution Guide
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/