Elmyr alternatives and similar libraries
Based on the "Tests" category.
Alternatively, view Elmyr alternatives based on common mentions on social networks and blogs.
-
Kotest
Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing and data driven testing -
kotlin-faker
https://serpro69.github.io/kotlin-faker/ Generate realistically looking fake data such as names, addresses, banking details, and many more, that can be used for testing and data anonymization purposes. -
hikaku
A library that tests if the implementation of a REST-API meets its specification. -
balin
Balin is an automation library for Kotlin. It's basically a Selenium-WebDriver wrapper inspired by Geb. -
SeleniumBuilder
Kotlin DSL for Selenium. Provide a possibility to write tests in Kotlin type-safe builders style -
arbitrater
Arbitrater is a Kotlin library for creating arbitrary instances of classes by reflection for use in testing. In contrast to POJO generators, it supports Kotlin's optional parameters and nullable types. -
aspen
Aspen is a simple test runner for Kotlin that allows you to write tests using your own DSL. -
mock-fuel
JUnit 5 extension to easily test with the http client Fuel for Kotlin
Appwrite - The Open Source Firebase alternative introduces iOS support
Do you think we are missing an alternative of Elmyr or a related project?
Popular Comparisons
README
Elmyr
Elmyr is a Kotlin library providing tools to generate “random” values, specifically useful for tests
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 theForge::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
andRegexForgery
- Allow advanced forgery injections using
@AdvancedForgery
and@MapForgery
junit5
- Allow injecting collections of primitives with
@BoolForgery
,@IntForgery
,@LongForgery
,@FloatForgery
,@DoubleForgery
, as well as@StringForgery
andRegexForgery
- Allow advanced forgery injections using
@AdvancedForgery
and@MapForgery
Donate
This library is completely free to use and modify (as per the [License](LICENSE.md)). 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.
Meta
Xavier F. Gouchet – @xgouchet
Distributed under the MIT license. See [LICENSE.md](LICENSE.md) for more information.
*Note that all licence references and agreements mentioned in the Elmyr README section above
are relevant to that project's source code only.