Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/naver/fixture-monkey

Let Fixture Monkey generate test instances including edge cases automatically
https://github.com/naver/fixture-monkey

java kotlin random-populated-object test

Last synced: 5 days ago
JSON representation

Let Fixture Monkey generate test instances including edge cases automatically

Awesome Lists containing this project

README

        

# Fixture Monkey
![Maven version](https://maven-badges.herokuapp.com/maven-central/com.navercorp.fixturemonkey/fixture-monkey/badge.svg)
[![Build](https://github.com/naver/fixture-monkey/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/naver/fixture-monkey/actions/workflows/build.yml)
[![GitHub license](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/naver/fixture-monkey/blob/main/LICENSE)


Designed by SeongIn Hong

### "Write once, Test anywhere"

Fixture Monkey is designed to easily generate controllable arbitrary instances. It allows you to reuse the same configurations of the instances in several tests.

You can write countless tests including edge cases, using just only one instance of the FixtureMonkey type. You can automatically generate instances of complex types and set fields with values from builders of the ArbitraryBuilder type. The well-defined builders can be reused in any test.

Each primitive type property is generated by [Jqwik](https://github.com/jlink/jqwik) or [kotest-property](https://github.com/kotest/kotest).

## Requirements

* JDK 1.8 or higher
* Jqwik 1.7.3
* Kotlin 1.8 or higher
* kotest-property 5.9.1

## Install

### Gradle

#### Java

```groovy
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:1.1.6")
```

#### Kotlin

```groovy
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1.1.6")
```

### Maven

#### Java

```xml

com.navercorp.fixturemonkey
fixture-monkey-starter
1.1.6
test

```

#### Kotlin

```xml

com.navercorp.fixturemonkey
fixture-monkey-starter-kotlin
1.1.6
test

```

## Example
> Add "lombok.anyConstructor.addConstructorProperties=true" in lombok.config

#### Java

```java
@Value
public class Order {
Long id;

String orderNo;

String productName;

int quantity;

long price;

List items;

Instant orderedAt;
}

@Test
void sampleOrder() {
// given
FixtureMonkey sut = FixtureMonkey.builder()
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
.build();

// when
Order actual = sut.giveMeBuilder(Order.class)
.set(javaGetter(Order::getOrderNo), "1")
.set(javaGetter(Order::getProductName), "Line Sally")
.minSize(javaGetter(Order::getItems), 1)
.sample();

// then
then(actual.getOrderNo()).isEqualTo("1");
then(actual.getProductName()).isEqualTo("Line Sally");
then(actual.getItems()).hasSizeGreaterThanOrEqualTo(1);
}
```

#### Kotlin

```kotlin
data class Order (
val id: Long,

val orderNo: String,

val productName: String,

val quantity: Int,

val price: Long,

val items: List,

val orderedAt: Instant
)

@Test
fun sampleOrder() {
// given
val sut = FixtureMonkey.builder()
.plugin(KotlinPlugin())
.build()

// when
val actual = sut.giveMeBuilder()
.setExp(Order::orderNo, "1")
.setExp(Order::productName, "Line Sally")
.minSizeExp(Order::items, 1)
.sample()

// then
then(actual.orderNo).isEqualTo("1")
then(actual.productName).isEqualTo("Line Sally")
then(actual.items).hasSizeGreaterThanOrEqualTo(1)
}
```

## Documentation
* [English](https://naver.github.io/fixture-monkey)
* [Korean](https://naver.github.io/fixture-monkey/v1-1-0-kor/)

## [FAQ](https://naver.github.io/fixture-monkey/v1-0-0/docs/cheat-sheet/faq/)

## [Third-party Modules](https://naver.github.io/fixture-monkey/docs/plugins/)

## Plugins
* [FixtureMonkey Helper](https://plugins.jetbrains.com/plugin/19589-fixturemonkey-helper)
- IntelliJ plugin that makes it easier to use Fixture Monkey string expressions & Kotlin DSL

## Contributors
* ๐Ÿ’ [ah.jo](https://github.com/seongside)
* ๐Ÿ’ [mhyeon-lee](https://github.com/mhyeon-lee)
* ๐Ÿ’ [acktsap](https://github.com/acktsap)
* ๐Ÿ’ [benelog](https://github.com/benelog)
* ๐Ÿ’ [jwChung](https://github.com/jwChung)
* ๐Ÿ’ [SooKim1110](https://github.com/SooKim1110)

Thanks to all [contributors](https://github.com/naver/fixture-monkey/graphs/contributors)

## More about Fixture Monkey
* [Deview 2021](https://tv.naver.com/v/23650158)

## Articles
* [fixure monkey๋กœ ์˜ˆ์™ธ ๋ฐœ์ƒ ํ…Œ์ŠคํŠธ](https://yangbongsoo.tistory.com/68?category=982054)
* [ํ…Œ์ŠคํŠธ ๊ฐ์ฒด๋ฅผ ๋”์‰ฝ๊ฒŒ ๋งŒ๋“ค์–ด๋ณด์ž, Fixture-monkey](https://taes-k.github.io/2021/12/12/fixture-monkey/)
* [Junit Test with Fixture Monkey](https://kevin-park.medium.com/junit-test-with-fixture-monkey-ca50f6533385)
* [Fixture monkey](https://leeheefull.tistory.com/m/27)
* [ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋„๊ตฌ - Fixture Monkey](https://jiwondev.tistory.com/272)
* [Fixture Monkey๋ž€?](https://velog.io/@pang_e/Fixture-Monkey%EB%9E%80)
* [ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ๋ฐ–์— ์—†๋Š” ์‚ฌ๋žŒ๋“ค์—๊ฒŒ](https://brunch.co.kr/@seongside/3)
* [Fixture Monkey ์‚ฌ์šฉํ•ด๋ณด๊ธฐ](https://codinghejow.tistory.com/419)
* [Simplify Unit Testing with Fixture Monkey](https://medium.com/naver-platform-labs/simplify-unit-testing-with-fixture-monkey-a-concise-pragmatic-and-interoperable-fixture-library-3bf0206258d4)
* [Getting Started Easy Test Fixture Customization with Fixture Monkey](https://medium.com/naver-platform-labs/easy-test-fixture-customization-with-fixture-monkey-4114c6b4b1ef)
* [[Fixture Monkey] ํ”ฝ์Šค์ณ ๋ชฝํ‚ค๋กœ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ (Java Spring)](https://sunshower99.tistory.com/33)
* [TestFixture๋ฅผ ์‰ฝ๊ฒŒ ์ƒ์„ฑํ•ด ์ฃผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ๋‹ค?](https://oliveyoung.tech/blog/2024-04-01/testcode-use-fixture-monkey/)
* [Fixture Monkey๋กœ ํ…Œ์ŠคํŠธ ํ”ฝ์Šค์ฒ˜๋ฅผ ์‰ฝ๊ฒŒ ์ƒ์„ฑํ•˜๊ณ  ๋ฆฌํŒฉํ† ๋ง ํ•ด๋ณด์ž](https://jxmen.github.io/wiki/project/cs-ai-interviewer/refactoring-with-fixture-monkey/)
* [Fixture Monkey๋ฅผ ์ ์šฉํ•ด๋ณด์ž w/JPA Test](https://currenjin.github.io/wiki/fixture-monkey-with-jpa/#fixture-monkey%EB%A5%BC-%EC%A0%81%EC%9A%A9%ED%95%B4%EB%B3%B4%EC%9E%90)

Welcome to write articles about Fixture Monkey!
Please let us know if you'd like to share your post.

## License

```
Copyright 2021-present NAVER Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```