Fixture Monkey is designed to easily generate fully-customizable, randomly populated instance. It allows you to focus on the properties of the class that really matter in your test.
It can help you write deterministic tests by generating a random instance of a class with specific property values. Focus on what you really matters in your test, and let Fixture Monkey handle the rest.
It is a good choice to support both DRY (Don't Repeat Yourself) and DAMP (Descriptive And Meaningful Phrases) principles in your test code.
It is interoperable with almost all test frameworks and libraries, including JUnit, TestNG, Kotest. It also supports Java and Kotlin. Each primitive type property is generated by Jqwik or kotest-property.
- JDK 1.8 or higher
- Jqwik 1.7.3
- Kotlin 1.8 or higher
- kotest-property 5.9.1
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:1.1.8")
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1.1.8")
<dependency>
<groupId>com.navercorp.fixturemonkey</groupId>
<artifactId>fixture-monkey-starter</artifactId>
<version>1.1.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.navercorp.fixturemonkey</groupId>
<artifactId>fixture-monkey-starter-kotlin</artifactId>
<version>1.1.8</version>
<scope>test</scope>
</dependency>
Add "lombok.anyConstructor.addConstructorProperties=true" in lombok.config
@Value
public class Order {
Long id;
String orderNo;
String productName;
int quantity;
long price;
List<String> 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);
}
data class Order (
val id: Long,
val orderNo: String,
val productName: String,
val quantity: Int,
val price: Long,
val items: List<String>,
val orderedAt: Instant
)
@Test
fun sampleOrder() {
// given
val sut = FixtureMonkey.builder()
.plugin(KotlinPlugin())
.build()
// when
val actual = sut.giveMeBuilder<Order>()
.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)
}
- FixtureMonkey Helper
- IntelliJ plugin that makes it easier to use Fixture Monkey string expressions & Kotlin DSL
- 🐒 ah.jo
- 🐒 mhyeon-lee
- 🐒 acktsap
- 🐒 benelog
- 🐒 jwChung
- 🐒 SooKim1110
Thanks to all contributors
- fixure monkey로 예외 발생 테스트
- 테스트 객체를 더쉽게 만들어보자, Fixture-monkey
- Junit Test with Fixture Monkey
- Fixture monkey
- 테스트 데이터도구 - Fixture Monkey
- Fixture Monkey란?
- 테스트를 작성할 수 밖에 없는 사람들에게
- Fixture Monkey 사용해보기
- Simplify Unit Testing with Fixture Monkey
- Getting Started Easy Test Fixture Customization with Fixture Monkey
- [Fixture Monkey] 픽스쳐 몽키로 테스트 코드 작성하기 (Java Spring)
- TestFixture를 쉽게 생성해 주는 라이브러리가 있다?
- Fixture Monkey로 테스트 픽스처를 쉽게 생성하고 리팩토링 해보자
- Fixture Monkey를 적용해보자 w/JPA Test
Welcome to write articles about Fixture Monkey! Please let us know if you'd like to share your post.
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.