Elmyr
Elmyr is a Kotlin library providing tools to generate “random” values, specifically usefull 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:0.5'
}JUnit
Elmyr provides a JUnit Rule that you can use to make your tests reproducible.
public class FooTest {
@Rule public JUnitForger forger = new JUnitForger();
@Test
public void shouldDoSomething(){
int base = forger.aPositiveInt();
int result = square(base);
assertThat(result).isEqualTo(base * base);
}
}Documentation
The full documentation can be read on ReadTheDocs.
Contributing
Contribution is fully welcome. Before submitting a Pull Request, please verify you comply with the following checklist :
- All public classes, methods and fields must be documented
- All code must be unit tested (duh…)
- All code should be useable with and without the Android SDK, from Java and Kotlin
Release History
0.5
- Create Strings from CharConstraint
- Add forgery for String arrays
For more information, read the Changelog.
Meta
Xavier F. Gouchet – @xgouchet
Distributed under the MIT license. See LICENSE.md for more information.