Genything is a framework for random testing of a program properties.

Related tags

Testing Genything
Overview

Swift Platforms CocoaPods Compatible Swift Package Manager

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/

Comments
  • Replace test functionality such that the library does not import XCTest

    Replace test functionality such that the library does not import XCTest

    In order to solve some annoying issues when importing the library from SPM

    https://forums.swift.org/t/xcode-not-respecting-canimport-xctest/46826 https://forums.swift.org/t/dynamically-call-xctfail-in-spm-module-without-importing-xctest/36375

    Removed XCTest as a dependency in favour of dynamically invoking XCTFail, hidden with a #if DEBUG flag. In non-debug situations the function will perform a no-op.

    This also removes the additional test library from the package.

    bug breaking 
    opened by nicorichard 0
  • Random Source parameterization for arbitrary collection sizes

    Random Source parameterization for arbitrary collection sizes

    Wouldn't mind some commentary on naming or if this should be nested into a configuration. But this change was a long time coming and I think better than forcing arbitrary defaults in a way that is not configurable whatsoever.

    Allows parameterization for the max "size" of arbitrary collections. In order to be truly arbitrary they would need to be infinite, but this is of course not feasible.

    opened by nicorichard 0
  • Arbitrary Dictionary Optimization

    Arbitrary Dictionary Optimization

    We were generating a random amount of values for a random amount of keys.

    Then the Swift standard zip was taking the shorter length of the two

    If the two sequences passed to zip(::) are different lengths, the resulting sequence is the same length as the shorter sequence.

    With this change no wasted generations will occur as the length of the keys will be used for the values.

    opened by nicorichard 0
  • Composing generators playground

    Composing generators playground

    https://user-images.githubusercontent.com/104579912/167923005-4de1eb63-be44-4d6b-a32b-0e03355c6141.mov

    Develop Composing with Operators Playground. There are a lot of operators already done and some being developed, so I added a base with some important ones. Created with rendered markup.

    opened by rafaeloliveira13 0
  • Make all the Generator structs internal. Expose the previously internal operators

    Make all the Generator structs internal. Expose the previously internal operators

    • Added variadics for some operators/generators
    • Made Generator structs internal, they can be useful
    • Namespaced the generator structs on the Generators enum extension
    • Exposed the previously internal operators (filter, distinct)
    • renamed startWith to prepend to match Combine
    opened by nicorichard 0
  • Add a drop function (like Sequence, Combine)

    Add a drop function (like Sequence, Combine)

    Drops n values from the generator or random source.

    Could be used to catch up to a previous execution time, if for instance you knew that your test failed with seed X on iteration N.

    You could run with RandomSource.replay(seed: X) and advance "time" with dropFirst(N)

    opened by nicorichard 0
  • GeneratorProfiler - Measure a generators performance

    GeneratorProfiler - Measure a generators performance

    Adds GeneratorProfiler which can be used to measure a generator's performance.

    The profiler is independent from all other functionalities (it could exist in another package, or target).

    Performance is measured by two key factors. Time and randomizations.

    Randomizations

    Counting randomizations gives us a sense of how often the generator must "throw out" a value.

    Most of the generators and operators we provide never do this, but some do:

    e.g. filter throws out values to find one which satisfies the filter, this adds 0...Infinity randomizations to the count e.g. either performs a coin-flip to choose between two generators, this adds a randomization to the count for each value

    Time

    Time is simply a measure of how long it took to generate each value, we measure total, average, best, and worst.

    printReport() sample output for Integers filtered to be even (n mod 2 == 0):

    == Profile: GenythingTests/GeneratorProfiler.swiftL20 ==
    == Generation ==
        total : 1000
    == Randomization ==
        total : 2033
        best  : 1
        worst : 10
        avg   : 2.033
    == Timing ==
        total : 0.0004163980484008789
        best  : 0.0
        worst : 1.1920928955078125e-05
        avg   : 4.163980484008789e-07
    
    opened by nicorichard 0
  • Rewrite entered around Generator as Protocol

    Rewrite entered around Generator as Protocol

    • Simplified Context down to just a barebones RandomSource
    • Removed the error handling completely in favour of more simplistic functions and protection against dangerous actions
    • Removed safe extensions
    • Internalized the most dangerous functions (filter, unique -> distinct) while a decision is made about the best way to handle these
    • Added new ways to manipulate data which are safer (recompose, regenerate)
    • Generator is now a Protocol and all extensions have been moved to the Protocol
    • operators and generators mostly moved to classes or structs which inherit the protocol rather than anonymous closure compositions
    • added some educational playgrounds
    • added a Sourcery template to auto conform to Arbitrary
    • Moved static generator creators to a Generators enum namespace, mimicking the Combine pattern
    • Organized and improved the codebase
    • Added swift format definitions and formatted the complete codebase
    • Added a wrapper for Generator to simplify value production (RandomizedGenerator)
    • Added a wrapper for Generator to simplify sharing a stateful generator without incurring side-effects (LazyGenerator)
    • Made both test functions have the same APIs and extend XCTestCase (testAll, testAllSatisfy)
    • Included stateful generators (Loop, Iterate, ShuffleLoop) to more easily consume the entire problem space
    opened by nicorichard 0
  • Generate sequences from generators

    Generate sequences from generators

    Rather than closure-based methods for drawing values such as the previously used forEach and take by utilizing sequences we can use more built-in Swift features such as for-in

    ex:

    for number in Int.arbitrary.sequence(size: 10) {
        print(number)
    }
    // prints 10 random integers
    
    opened by nicorichard 0
  • Stateful generator improvements and preparation

    Stateful generator improvements and preparation

    • Added internal generator switching method to facilitate stateful generators
    • Fixed inContext to be properly stateful as intended
    • Added shuffleDistribution
    • Simplified iterate & looping & startWith using switch
    • Removed leaky Context-held state and put it on the Generator
    • Preparing for the separation of stateful and stateless generatable creators and generators
    opened by nicorichard 0
  • Additions:

    Additions: "Also" for side-effects and "debug" for printing debug messages

    Creates a debug function which can be used to log print statements to aid in debugging

    e.g.

    Gen
        .from(1...5)
        .debug()
        .map { $0 * 2 }
        .debug("*2")
        .take(5)
    

    will produce:

    14:22:42.205: [GenythingTests/GenDebugTests.swift:8] -> 5
    14:22:42.205: [*2] -> 10
    14:22:42.205: [GenythingTests/GenDebugTests.swift:8] -> 4
    14:22:42.205: [*2] -> 8
    14:22:42.205: [GenythingTests/GenDebugTests.swift:8] -> 3
    14:22:42.205: [*2] -> 6
    

    In addition I've added also to the toolkit which was used to make debug possible.

    also can be used to introduce side-effects during value generation, something that I wouldn't really recommend unless perhaps to implement a different logging/debugging solution.

    opened by nicorichard 0
Releases(1.0.0)
  • 1.0.0(May 25, 2022)

    What's Changed

    • Adds a method to allow for array shuffling by @nicorichard in https://github.com/justeattakeaway/Genything/pull/31
    • Adds a weighted probability gen builder by @nicorichard in https://github.com/justeattakeaway/Genything/pull/32
    • Additions: "Also" for side-effects and "debug" for printing debug messages by @nicorichard in https://github.com/justeattakeaway/Genything/pull/33
    • Stateful generator improvements and preparation by @nicorichard in https://github.com/justeattakeaway/Genything/pull/34
    • Composer simplification by @nicorichard in https://github.com/justeattakeaway/Genything/pull/35
    • Generate sequences from generators by @nicorichard in https://github.com/justeattakeaway/Genything/pull/36
    • Adds scan and replaceNil operators by @nicorichard in https://github.com/justeattakeaway/Genything/pull/37
    • Rewrite entered around Generator as Protocol by @nicorichard in https://github.com/justeattakeaway/Genything/pull/38
    • Remove the default constructor from random source by @nicorichard in https://github.com/justeattakeaway/Genything/pull/39
    • Add canImport compile directive protection to all xctest imports by @nicorichard in https://github.com/justeattakeaway/Genything/pull/41
    • GeneratorProfiler - Measure a generators performance by @nicorichard in https://github.com/justeattakeaway/Genything/pull/40
    • Add a merge generator by @nicorichard in https://github.com/justeattakeaway/Genything/pull/42
    • Switch documentation to Docc by @nicorichard in https://github.com/justeattakeaway/Genything/pull/43
    • Intro playground by @magaliet in https://github.com/justeattakeaway/Genything/pull/44
    • Add a drop function (like Sequence, Combine) by @nicorichard in https://github.com/justeattakeaway/Genything/pull/45
    • Make all the Generator structs internal. Expose the previously internal operators by @nicorichard in https://github.com/justeattakeaway/Genything/pull/46
    • Provide a flatten operator by @nicorichard in https://github.com/justeattakeaway/Genything/pull/47
    • Composing generators playground by @rafaeloliveira13 in https://github.com/justeattakeaway/Genything/pull/48
    • Flatten for meta-generators by @nicorichard in https://github.com/justeattakeaway/Genything/pull/49
    • Intro playground cleanup by @magaliet in https://github.com/justeattakeaway/Genything/pull/50
    • Improve our playground for modelling production data by @nicorichard in https://github.com/justeattakeaway/Genything/pull/51
    • Arbitrary Dictionary Optimization by @nicorichard in https://github.com/justeattakeaway/Genything/pull/52
    • Intro playground by @magaliet in https://github.com/justeattakeaway/Genything/pull/54
    • Improve the playground following presentation by @nicorichard in https://github.com/justeattakeaway/Genything/pull/55
    • Random Source parameterization for arbitrary collection sizes by @nicorichard in https://github.com/justeattakeaway/Genything/pull/53

    New Contributors

    • @rafaeloliveira13 made their first contribution in https://github.com/justeattakeaway/Genything/pull/48

    Full Changelog: https://github.com/justeattakeaway/Genything/compare/0.0.4...1.0.0

    Source code(tar.gz)
    Source code(zip)
  • 0.0.4(Feb 11, 2022)

    • Basic edgecase handling by @nicorichard in https://github.com/justeattakeaway/Genything/pull/28
    • 3 new sequence-based operators by @nicorichard in https://github.com/justeattakeaway/Genything/pull/29
    • Safe gen improvements by @nicorichard in https://github.com/justeattakeaway/Genything/pull/30

    Full Changelog: https://github.com/justeattakeaway/Genything/compare/0.0.3...0.0.4

    Source code(tar.gz)
    Source code(zip)
  • 0.0.3(Dec 7, 2021)

    What's Changed

    • Procedural images by @nortonpmjr in https://github.com/justeattakeaway/Genything/pull/16
    • Fixed broken pbxproj by @nortonpmjr in https://github.com/justeattakeaway/Genything/pull/18
    • Add documentation by @CityTransit in https://github.com/justeattakeaway/Genything/pull/19
    • Generate the polygons again! by @CityTransit in https://github.com/justeattakeaway/Genything/pull/20
    • Improve the readme by @CityTransit in https://github.com/justeattakeaway/Genything/pull/21
    • Test! by @CityTransit in https://github.com/justeattakeaway/Genything/pull/22
    • Fake.Icons.sfSymbols by @magaliet in https://github.com/justeattakeaway/Genything/pull/13
    • Show off using 3rd party libs like SFSafeSymbols in the Example app and README by @CityTransit in https://github.com/justeattakeaway/Genything/pull/23
    • Generate unique values. 100% documented! by @CityTransit in https://github.com/justeattakeaway/Genything/pull/24
    • XCTesting Module by @CityTransit in https://github.com/justeattakeaway/Genything/pull/25
    • Add a reduce method. Provide example. by @CityTransit in https://github.com/justeattakeaway/Genything/pull/26
    • Context super powers by @CityTransit in https://github.com/justeattakeaway/Genything/pull/27

    Full Changelog: https://github.com/justeattakeaway/Genything/compare/0.0.2...0.0.3

    Source code(tar.gz)
    Source code(zip)
  • 0.0.2(Nov 17, 2021)

    What's Changed

    • Increase test coverage by @kedio in https://github.com/justeattakeaway/Genything/pull/1
    • Renamed package from Generator to Genything in GenythingExample project by @magaliet in https://github.com/justeattakeaway/Genything/pull/2
    • Added a small CONTRIBUTING guide to the project by @nortonpmjr in https://github.com/justeattakeaway/Genything/pull/3
    • Make the context more powerful, Improve and organize Producers, add documentation and cleaned up tests by @CityTransit in https://github.com/justeattakeaway/Genything/pull/4
    • Fake.Addresses.postalCode by @kedio in https://github.com/justeattakeaway/Genything/pull/5
    • Raise the acceptable delta for oneOf tests by @CityTransit in https://github.com/justeattakeaway/Genything/pull/7
    • Fakes for BusinessNames by @magaliet in https://github.com/justeattakeaway/Genything/pull/6
    • Code commenting and Zip improvements by @CityTransit in https://github.com/justeattakeaway/Genything/pull/8
    • Add Jazzy documentation by @CityTransit in https://github.com/justeattakeaway/Genything/pull/9
    • Fake addresses parts by @kedio in https://github.com/justeattakeaway/Genything/pull/10
    • Test for Fake.PersonNames, Fake.PhoneNumber + zip accessibility fix by @magaliet in https://github.com/justeattakeaway/Genything/pull/12
    • BusinessListView Example by @magaliet and @kedio in https://github.com/justeattakeaway/Genything/pull/11
    • Another demo idea, consolidate replacing occurrences logic by @CityTransit in https://github.com/justeattakeaway/Genything/pull/14
    • Add logo to readme and the demo's app icon by @CityTransit in https://github.com/justeattakeaway/Genything/pull/17
    • Fake.emails by @kedio in https://github.com/justeattakeaway/Genything/pull/15

    Full Changelog: https://github.com/justeattakeaway/Genything/compare/0.0.1...0.0.2

    Source code(tar.gz)
    Source code(zip)
Owner
Just Eat Takeaway.com
Food is our passion. Tech is our power.
Just Eat Takeaway.com
Switchboard - easy and super light weight A/B testing for your mobile iPhone or android app. This mobile A/B testing framework allows you with minimal servers to run large amounts of mobile users.

Switchboard - easy A/B testing for your mobile app What it does Switchboard is a simple way to remote control your mobile application even after you'v

Keepsafe 287 Nov 19, 2022
Testing the UI without UI Testing, a Swift experiment.

UI tests without UI Testing experiment This repo is a small experiment to see if there's an "in-between" for testing iOS applications. More feature-le

Joe Masilotti 20 Sep 26, 2022
Trying to implement Unit Tests for @Binding properties in a ViewModel

BindingTester Trying to implement Unit Tests for @Binding properties in a ViewModel ViewModel to be tested class SheetViewModel: ObservableObject {

Raphael Guye 0 Oct 22, 2021
The Swift (and Objective-C) testing framework.

Quick is a behavior-driven development framework for Swift and Objective-C. Inspired by RSpec, Specta, and Ginkgo. // Swift import Quick import Nimbl

Quick 9.6k Dec 31, 2022
Remote configuration and A/B Testing framework for iOS

MSActiveConfig v1.0.1 Remote configuration and A/B Testing framework for iOS. Documentation available online. MSActiveConfig at a glance One of the bi

Elevate 78 Jan 13, 2021
AB testing framework for iOS

ABKit Split Testing for Swift. ABKit is a library for implementing a simple Split Test that: Doesn't require an HTTP client written in Pure Swift Inst

Recruit Marketing Partners Co.,Ltd 113 Nov 11, 2022
Keep It Functional - An iOS Functional Testing Framework

IMPORTANT! Even though KIF is used to test your UI, you need to add it to your Unit Test target, not your UI Test target. The magic of KIF is that it

KIF Framework 6.2k Dec 29, 2022
T - A simple testing framework using closures and errors

t Quickly test expectations What is t? t is a simple testing framework using clo

OpenBytes 6 Nov 7, 2022
Network testing for Swift

DVR DVR is a simple Swift framework for making fake NSURLSession requests for iOS, watchOS, and OS X based on VCR. Easy dependency injection is the ma

Venmo 650 Nov 3, 2022
Snapshot testing tool for iOS and tvOS

SnapshotTest is a simple view testing tool written completely in Swift to aid with development for Apple platforms. It's like unit testing for views.

Pär Strindevall 44 Sep 29, 2022
UI Testing Cheat Sheet and Examples.

UI Testing Cheat Sheet This repository is complementary code for my post, UI Testing Cheat Sheet and Examples. The post goes into more detail with exa

Joe Masilotti 2.1k Dec 25, 2022
Mockingbird was designed to simplify software testing, by easily mocking any system using HTTP/HTTPS

Mockingbird Mockingbird was designed to simplify software testing, by easily mocking any system using HTTP/HTTPS, allowing a team to test and develop

FARFETCH 183 Dec 24, 2022
Automatic testing of your Pull Requests on GitHub and BitBucket using Xcode Server. Keep your team productive and safe. Get up and running in minutes. @buildasaur

Buildasaur Automatic testing of your Pull Requests on GitHub and BitBucket using Xcode Server. Keep your team productive and safe. Get up and running

Buildasaurs 774 Dec 11, 2022
Fastbot is a model-based testing tool for modeling GUI transitions to discover app stability problems

Fastbot is a model-based testing tool for modeling GUI transitions to discover app stability problems. It combines machine learning and reinforcement learning techniques to assist discovery in a more intelligent way.

Bytedance Inc. 446 Dec 29, 2022
Implementing and testing In-App Purchases with StoreKit2 in Xcode 13, Swift 5.5 and iOS 15.

StoreHelper Demo Implementing and testing In-App Purchases with StoreKit2 in Xcode 13, Swift 5.5, iOS 15. See also In-App Purchases with Xcode 12 and

Russell Archer 192 Dec 17, 2022
For Testing APIs of NYTimes

NYTimes-APIs For Testing APIs of NYTimes Mark Dennis Diwa ?? To run the app: Open terminal first then run pod install. Open workspace. Run the app on

Mark Dennis Diwa 0 Nov 23, 2021
A Mac and iOS Playgrounds Unit Testing library based on Nimble.

Spry Spry is a Swift Playgrounds Unit Testing library based on Nimble. The best thing about Spry is that the API matches Nimble perfectly. Which means

Quick 327 Jul 24, 2022
Multivariate & A/B Testing for iOS and Mac

This library is no longer being maintained. You can continue to use SkyLab in your projects, but we recommend switching another solution whenever you

Mattt 792 Dec 15, 2022
AppiumLibrary is an appium testing library for RobotFramework

Appium library for RobotFramework Introduction AppiumLibrary is an appium testing library for Robot Framework. Library can be downloaded from PyPI. It

Serhat Bolsu 327 Dec 25, 2022