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 or kotest-property.
- JDK 1.8 or higher
- Jqwik 1.7.3
- Kotlin 1.8 or higher
- kotest-property 5.6.2
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:1.0.28")
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1.0.28")
<dependency>
<groupId>com.navercorp.fixturemonkey</groupId>
<artifactId>fixture-monkey-starter</artifactId>
<version>1.0.28</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.navercorp.fixturemonkey</groupId>
<artifactId>fixture-monkey-starter-kotlin</artifactId>
<version>1.0.28</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.