GithubHelp home page GithubHelp logo

jacobhboy / fixture-monkey Goto Github PK

View Code? Open in Web Editor NEW

This project forked from naver/fixture-monkey

0.0 0.0 0.0 19.02 MB

Let Fixture Monkey generate test instances including edge cases automatically

Home Page: https://naver.github.io/fixture-monkey

License: Apache License 2.0

Java 83.45% Kotlin 16.55%

fixture-monkey's Introduction

Fixture Monkey

Maven version Build GitHub 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 or kotest-property.

Requirements

  • JDK 1.8 or higher
  • Jqwik 1.7.3
  • Kotlin 1.8 or higher
  • kotest-property 5.6.2

Install

Gradle

Java

testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:1.0.4")

Kotlin

testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter-kotlin:1.0.4")

Maven

Java

<dependency>
    <groupId>com.navercorp.fixturemonkey</groupId>
    <artifactId>fixture-monkey-starter</artifactId>
    <version>1.0.4</version>
    <scope>test</scope>
</dependency>

Kotlin

<dependency>
    <groupId>com.navercorp.fixturemonkey</groupId>
    <artifactId>fixture-monkey-starter-kotlin</artifactId>
    <version>1.0.4</version>
    <scope>test</scope>
</dependency>

Example

Add "lombok.anyConstructor.addConstructorProperties=true" in lombok.config

Java

@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);
}

Kotlin

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)
}

Documentation

Plugins

  • FixtureMonkey Helper
    • IntelliJ plugin that makes it easier to use Fixture Monkey string expressions & Kotlin DSL

Contributors

More about Fixture Monkey

Articles

Welcome to write articles about Fixture Monkey!

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.

fixture-monkey's People

Contributors

seongahjo avatar sookim1110 avatar acktsap avatar mhyeon-lee avatar benelog avatar chanhyeong avatar sangy515 avatar jwchung avatar doljae avatar byungjunyou avatar dbgsprw avatar imbyungjun avatar jbl428 avatar jongwooo avatar kshired avatar sandrawangyx avatar yn-jn-j avatar esfomeado avatar wicksome avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.