All Projects → xgouchet → Elmyr

xgouchet / Elmyr

Licence: other
A utility to make Kotlin/Java tests random yet reproducible

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to Elmyr

Pystdf
Python module for working with STDF files
Stars: ✭ 74 (+8.82%)
Mutual labels:  hacktoberfest, test
Kotlinfixture
Fixtures for Kotlin providing generated values for unit testing
Stars: ✭ 94 (+38.24%)
Mutual labels:  hacktoberfest, test
Test Each
🤖 Repeat tests. Repeat tests. Repeat tests.
Stars: ✭ 89 (+30.88%)
Mutual labels:  test, fuzzing
Atoum
The modern, simple and intuitive PHP unit testing framework.
Stars: ✭ 1,382 (+1932.35%)
Mutual labels:  hacktoberfest, test
Alsatian
TypeScript testing framework with test cases
Stars: ✭ 244 (+258.82%)
Mutual labels:  hacktoberfest, test
Faker
Faker is a pure Elixir library for generating fake data.
Stars: ✭ 673 (+889.71%)
Mutual labels:  hacktoberfest, test
Rebar3
Erlang build tool that makes it easy to compile and test Erlang applications and releases.
Stars: ✭ 1,295 (+1804.41%)
Mutual labels:  hacktoberfest, test
Grammarinator
ANTLR v4 grammar-based test generator
Stars: ✭ 162 (+138.24%)
Mutual labels:  hacktoberfest, fuzzing
Fuzzinator
Fuzzinator Random Testing Framework
Stars: ✭ 164 (+141.18%)
Mutual labels:  hacktoberfest, fuzzing
Unity Actions
Github actions for testing and building Unity projects
Stars: ✭ 358 (+426.47%)
Mutual labels:  hacktoberfest, test
Cli Prompts Test
Write e2e tests for CLI apps with ease
Stars: ✭ 17 (-75%)
Mutual labels:  hacktoberfest, test
Ideogram
Insert emoji anywhere in elementary OS, even in non-native apps
Stars: ✭ 68 (+0%)
Mutual labels:  hacktoberfest
Gulp Wp Pot
Gulp plugin to generate pot file for WordPress plugins and themes
Stars: ✭ 67 (-1.47%)
Mutual labels:  hacktoberfest
Activity
⚡️ Activity app for Nextcloud
Stars: ✭ 67 (-1.47%)
Mutual labels:  hacktoberfest
Ex mustang
✨ A simple, clueless bot
Stars: ✭ 67 (-1.47%)
Mutual labels:  hacktoberfest
Talisman
By hooking into the pre-push hook provided by Git, Talisman validates the outgoing changeset for things that look suspicious - such as authorization tokens and private keys.
Stars: ✭ 1,155 (+1598.53%)
Mutual labels:  hacktoberfest
Youtubeexplode.converter
Muxes and converts videos from YoutubeExplode
Stars: ✭ 68 (+0%)
Mutual labels:  hacktoberfest
Genesis
🤖 Warframe Discord Cephalon
Stars: ✭ 67 (-1.47%)
Mutual labels:  hacktoberfest
Portugol Webstudio
IDE online para o Portugol
Stars: ✭ 67 (-1.47%)
Mutual labels:  hacktoberfest
Book
📖 Guides and tutorials on how to fuzz Rust code
Stars: ✭ 67 (-1.47%)
Mutual labels:  fuzzing

Elmyr

Elmyr is a Kotlin library providing tools to generate “random” values, specifically useful for tests

Release Documentation Status

Build Status codecov

license Donate

Being an adept of testing code, I write a lot of tests. One thing I noticed is that in my tests, my fake / test data always look the same. My user names are always “Bob” and “Alice”, aged 42 or 69, with userId 4816152342 or 24601, and eating “spam”, “eggs” and “bacon”.

The problem is, the more test I write, the less I'm confident in my fake values, because they're always the same.

This is where Elmyr kicks in, allowing you to create fake/fuzzy data based on a few constraints, making your test data random, and yet reproducible.

Usage

Gradle

    repositories {
        maven { url "https://jitpack.io" }
    }
    dependencies {
        testCompile("com.github.xgouchet.Elmyr:core:x.x.x")
        testCompile("com.github.xgouchet.Elmyr:junit4:x.x.x")
        testCompile("com.github.xgouchet.Elmyr:junit5:x.x.x")
        testCompile("com.github.xgouchet.Elmyr:jvm:x.x.x")
    }

Forging data: the core module

You can create an instance of the Forge class, and from that generate:

  • primitives, with basic constraints
  • Strings matching simple predicates or even Regexes
  • Your own custom data, by implementing the ForgeryFactory interface, then calling the Forge::addFactory method.

ForgeRule for junit4

You can instantiate a ForgeRule instance, which extends the Forge class, add factories to it, and then annotate fields on your test class with @Forgery.

class FooTest {

    @get:Rule
    val forge = ForgeRule()
            .withFactory(FooFactory())
            .withFactory(BarFactory())

    @Forgery
    internal lateinit var fakeBar: Bar

    @Forgery
    lateinit var fakeFooList: List<Foo>

    //…
}

ForgeExtension for junit5

You can add an extension and configure it. In addition to creating forgeries on fields/properties of your test class, you can inject parameters directly on your test methods.

@ExtendWith(ForgeExtension::class)
@ForgeConfiguration(KotlinAnnotationTest.Configurator::class)
internal class FooTest {

    @Forgery
    internal lateinit var fakeBar: Bar

    @Forgery
    lateinit var fakeFooList: List<Foo>

    @Test
    fun testSomething(@IntForgery i: Int, forge:Forge){
        // …
    }
}

spek forgeries

You can create a custom Forge instance with spekForge to be able to add reproducibility to Spek tests.

class CalculatorSpek : Spek({

    val forge = spekForge(
        seeds = mapOf(
            "CalculatorSpek/A calculator/addition/returns the sum of its arguments" to 0x1337L
        )
    )

    describe("A calculator") {
        val calculator by memoized { Calculator() }
        
        describe("addition") {
            it("returns the sum of its arguments") {
                val a = forge.anInt()
                val b = forge.anInt()
                assertEquals(calculator.add(a, b), a + b)
            }
        }
    }
})

Documentation

The full documentation will be coming shortly

Contributing

Contribution is fully welcome. Before submitting a Pull Request, please verify you comply with the following checklist :

  • [x] All public classes, methods and fields must be documented
  • [x] All code must be unit tested (duh…)
  • [x] All code should be usable with and without the Android SDK, from Java and Kotlin

Release History

Latest Release: 1.2.0 (2020/09/03)

core

  • Allow using the @StringForgery annotation to forge Strings based on Regex
  • Allow setting a size in @StringForgery annotation

inject

  • Allow injecting collections of primitives with @BoolForgery, @IntForgery, @LongForgery, @FloatForgery, @DoubleForgery, as well as @StringForgery and RegexForgery
  • Allow advanced forgery injections using @AdvancedForgery and @MapForgery

junit5

  • Allow injecting collections of primitives with @BoolForgery, @IntForgery, @LongForgery, @FloatForgery, @DoubleForgery, as well as @StringForgery and RegexForgery
  • Allow advanced forgery injections using @AdvancedForgery and @MapForgery

Donate

This library is completely free to use and modify (as per the License). I try my best to make it as good as possible, but only do this on my free time. If you want to support my work, you can click the Donate button below.

paypal

Meta

Xavier F. Gouchet – @xgouchet

Distributed under the MIT license. See LICENSE.md for more information.

https://github.com/xgouchet/Elymr

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].