Coder Social home page Coder Social logo

xgouchet / elmyr Goto Github PK

View Code? Open in Web Editor NEW
81.0 81.0 2.0 940 KB

A utility to make Kotlin/Java tests random yet reproducible

License: Other

Kotlin 95.24% Java 4.76%
fuzzing hacktoberfest hacktoberfest2020 hacktoberfest2021 hacktoberfest2022 hacktoberfest2023 java kotlin test

elmyr's Introduction

Greetings stranger 👋

About… me

Hello, My name's Xavier F. Gouchet, I'm a french multipotentialite, Open Source enthusiast, Android software engineer and team leader, professional speaker and erstwhile teacher.

  • 🔭 I’m currently working on too many projects at the same time. Sci-fi books, music, Kotlin projects…
  • 🌱 I’m currently learning Roku development, and Android Jetpack Compose
  • 👯 I’m looking to collaborate on music, writing, code, …
  • 💬 Ask me about anything, among others Android, testing, Kotlin, Roku, creative writing, music, …
  • 🏳️‍🌈 Be kind to everyone

Reach out to me

Github Stats

Github stats

Top Langs

Years Badge Repos Badge Gists Badge Commits Badge

elmyr's People

Contributors

dependabot-preview[bot] avatar vitusortner avatar xgouchet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

elmyr's Issues

Make source code available as a JAR

Have you thought about making the project available as a JAR, to make the source code visible in an IDE, after downloading the package?

Adding this to the build.gradle does the trick:

task packageSources(type: Jar, dependsOn: 'classes') {
    from sourceSets.main.allSource
    classifier = 'sources'
}

artifacts { archives packageSources }

[JUnit5] Inject list of forgeries

In a Junit5 test, it would be nice to be able to write (assuming a Forgery of Foo is available) :

``
`
class A {
@forgery lateinit var fakeList : List

@Test
fun test(@Forgery list : List<Foo>) {
    // …
}

}
`
``

[JUnit5] Include ForgeConfiguration from parent class

@ ExtendWith(ForgeExtension::class)
@ForgeConfiguration(Configurator::class)
abstract class A {
}

class B : A() {
}

When running tests from B, the configurator is not found. It would be neat if Elmyr could find it automatically!

Sources still not visible

Even though I'm using the latest version of your library (0.8) the source code is still not visible for me, when viewing from an IDE.

Create list with provider

fun <T> createFakeList(forger: Forger, creator: (Forger) -> T): List<T> {
    val count = forger.aTinyInt()
    val list = ArrayList<T>(count)

    for (i in 0 until count) {
        list.add(creator(forger))
    }

    return list
}

Add Memoization to the RegexParser class

Right now, the RegexParser class will always parse the provided Regex. Adding a map/LRU/LFU of previously known regexes could improve the tests (especially since the same regex might be reused many times).

Can not set a seed with the default ForgeConfigurator

Hi,

I was just testing your lovely library after watching this video on youtube, and just got an error : I can not replay a test with a seed and the default ForgeConfigurator. It also happen with just @ForgeConfiguration (no seed and no Configurator provided)

class fr.xgouchet.elmyr.junit5.ForgeExtension cannot access a member of class fr.xgouchet.elmyr.ForgeConfigurator$NoOp with modifiers "private"
java.lang.IllegalAccessException: class fr.xgouchet.elmyr.junit5.ForgeExtension cannot access a member of class fr.xgouchet.elmyr.ForgeConfigurator$NoOp with modifiers "private"
	at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
	at java.base/jdk.internal.reflect.Reflection.ensureMemberAccess(Reflection.java:99)
	at java.base/java.lang.Class.newInstance(Class.java:579)
	at fr.xgouchet.elmyr.junit5.ForgeExtension.getConfigurators(ForgeExtension.kt:193)
	at fr.xgouchet.elmyr.junit5.ForgeExtension.beforeAll(ForgeExtension.kt:66)
	at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$7(ClassBasedTestDescriptor.java:359)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at 
[...]

Here is my very basic test class:

import fr.xgouchet.elmyr.annotation.IntForgery
import fr.xgouchet.elmyr.junit5.ForgeConfiguration
import fr.xgouchet.elmyr.junit5.ForgeExtension
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(ForgeExtension::class)
@ForgeConfiguration(seed = 0x2af7b7def4L)
class FooTest {
    @Test
    fun testSomething(@IntForgery i: Int) {
        i % 2 shouldBe 0
    }
}

version: 1.2.0
kotlin: 1.4.20
junit: 5.6.0

Crash with Repeater Rule if one test method is not annotated

java.lang.NullPointerException
	at fr.xgouchet.elmyr.junit.Repeater$apply$1.evaluate(Repeater.kt:25)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

Issue with Java 11

Since upgrading to 1.3.2, I have the following compile issue when testing : Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option

Could the libs be built with Java 8 ?

Alphanumerical characters contain "_"

ALPHA_NUM_UPPER and ALPHA_NUM_LOWER should not contain the _ character.
I see that they are used when generating a character with anAlphaNumericalChar method.

Also, is there an easier way to generate an alphanumerical String of fixed case and length?

Add customizable options for Urls

Let users customize URLs with custom scheme, hostname, tld etc...

eg :

forger.aUrl(scheme = "https", tld="com", queryParams=false)

Generate url that matches Patterns.WEB_URL

Hi!
Is it possible to generate url which matches Patterns.WEB_URL from Android?

 /**
     *  Regular expression pattern to match most part of RFC 3987
     *  Internationalized URLs, aka IRIs.
     */
    public static final Pattern WEB_URL = Pattern.compile("("
            + "("
            + "(?:" + PROTOCOL + "(?:" + USER_INFO + ")?" + ")?"
            + "(?:" + DOMAIN_NAME_STR + ")"
            + "(?:" + PORT_NUMBER + ")?"
            + ")"
            + "(" + PATH_AND_QUERY + ")?"
            + WORD_BOUNDARY
            + ")");

Forger.aUrl(scheme = "http") does not follow that standard.

Library is not compatible with Android SDK version lower than 24

I'm running into problems using your library for instrumented Android tests on devices running Android SDK version 21 and 23, when calling the Forger.aSentence() function.

The problem is caused by the Integer.min() function, which has only been added in Android version 24. So devices running older versions of Android are lacking the implementation.

I would suggest using the kotlin.math.min() function instead, which also uses Java's Math.min() under the hood.

Apart from that I enjoy using your library. Keep up the good work!

The error I got:
java.lang.NoSuchMethodError: No static method min(II)I in class Ljava/lang/Integer; or its super classes (declaration of 'java.lang.Integer' appears in /system/framework/core-libart.jar) at fr.xgouchet.elmyr.Forger.aSentence(Forger.kt:755) at fr.xgouchet.elmyr.Forger.aSentence$default(Forger.kt:735) ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.