Let Fixture Monkey generate test instances including edge cases automatically

Overview

Fixture Monkey

Maven version Build GitHub license

Designed by Judy Kim

"Write once, Test anywhere"

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

You can write countless tests including edge cases by only one instance of the FixtureMonkey type. You can generate instances of complex types automatically and set fields with values from builders of the ArbitraryBuilder type. The well-defined builders could be reused in any tests. Writing integration tests is easier with Fixture Monkey.

Each primitive type property is generated by Jqwik

Example

@Data   // lombok getter, setter
public class Order {
    @NotNull
    private Long id;

    @NotBlank
    private String orderNo;

    @Size(min = 2, max = 10)
    private String productName;

    @Min(1)
    @Max(100)
    private int quantity;

    @Min(0)
    private long price;

    @Size(max = 3)
    private List<@NotBlank @Size(max = 10) String> items = new ArrayList<>();

    @PastOrPresent
    private Instant orderedAt;

    @Email
    private String sellerEmail;
}

@Test
void test() {
    // given
    FixtureMonkey sut = FixtureMonkey.create();

    // when
    Order actual = sut.giveMeOne(Order.class);

    // then
    then(actual.getId()).isNotNull();
}

Requirements

  • JDK 1.8 or higher
  • Jqwik 1.3.9

Install

Gradle

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

Maven

<dependency>
    <groupId>com.navercorp.fixturemonkeygroupId>
    <artifactId>fixture-monkeyartifactId>
    <version>0.3.0version>
    <scope>testscope>
dependency>

Documentation

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

Third-party Modules

  • fixture-monkey-jackson
    • Supports jackson Serialize/Deserialize object generation.
  • fixture-monkey-kotlin
    • Supports Kotlin.
  • fixture-monkey-autoparams (Experimental)
    • Extends AutoParams to support parameterized tests.
  • fixture-monkey-mockito (Experimental)
    • Supports for generating interfaces and abstract classes as mockito objects.

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.
Comments
  • Generator on kotlin secondary constructor

    Generator on kotlin secondary constructor

    secondary constructor에 대한 generator

    한개만 있으면 그걸 사용하고 여러개가 있을 경우 annotation을 사용해서 mark

    data class A(val value: Int) {
         constructor() : this(0) {
             // do something
         }
    
         @SecondaryConstructor // 이런 식으로
         constructor(val value: String) : this(value.toInt()) {
             // do something
         }
    
    }
    
    enhancement 
    opened by acktsap 8
  • Add generating a circular-reference object

    Add generating a circular-reference object

    Summary

    Add generating a circular-reference object

    (Optional): Description

    순환참조일 경우 1-depth까지만 생성합니다.

    For example,

    class A {
       B b;
    }
    
    class B {
       A a;
    }
    
    A a = fixture.giveMeOne(A.class);
    
    {
        "b" :  {
            "a" : {
                "b" : null
            }
       }
    }
    
    

    How Has This Been Tested?

    • sampleSelfRecursiveObject
    • sampleSelfRecursiveList
    • sampleRecursiveObject

    resolves #495

    opened by seongahjo 6
  • Refactor build as private

    Refactor build as private

    ArbitraryBuilder 인터페이스에서 jqwik의 Arbitrary 의존성을 제거하기 위해 build를 private으로 변경하여 클라이언트에게 노출하지 않습니다.

    이런 결정을 한 이유는 다음과 같습니다.

    1. jqwik이 버전업될 때마다 breaking change가 생길 위험이 있다.
    2. Fixture Monkey에서 만들어진 Arbitrary는 apply, acceptIf 등의 복잡한 연산을 사용하는 경우 jqwik에서 정의한 연산을 의도대로 지원하기 어렵다.
    3. 사용자는 Arbitrary 인터페이스에서 극히 일부 메소드만 사용한다.
    4. Arbitrary 인터페이스 지원은 Fixture Monkey 기능 확장을 방해한다.
    opened by seongahjo 5
  • Specify FixtureMonkey instance as a non-null type

    Specify FixtureMonkey instance as a non-null type

    This PR ensures the KFixtureMonkey instance is a non-null type. So, fix the warning below. This warning is propagated to your source code. image

    I think that specifying it as non-null type on KFixtureMonkey(like below) would be a workaround.

    object KFixtureMonkey {
        fun create(): FixtureMonkey = KFixtureMonkeyBuilder().build()
    }
    

    But, specifying the @Nonnull annotation looks proper solution.

    opened by imbyungjun 5
  • Add fixture-monkey-api module for spi interfaces

    Add fixture-monkey-api module for spi interfaces

    확장을 지원할 spi Interface 들을 제공하는 fixture-monkey-api 모듈을 추가합니다. fixture-monkey 에서 확장을 지원할 인터페이스는 여기에 추가하고, 기존 인터페이스는 @Deprecated 처리합니다. fixture-monkey-jackson, fixture-monkey-mockito 도 fixture-monkey 를 바로 의존하는 것이 아니라 fixture-monkey-api 를 의존하고 필요한 구현체를 제공하도록 수정합니다.

    Deprecated 된 fixture-monkey 의 인터페이스는 0.5.0 에서 제거합니다.

    opened by mhyeon-lee 5
  • Refactor ArbitraryValue methods return Arbitrary

    Refactor ArbitraryValue methods return Arbitrary

    우선 Arbitrary를 반환값으로 가지는 경우만 처리했습니다. Arbitrary를 반환할 때 ArbitraryValue를 반환해서 sample, sampleStream을 실행하는 시점을 추적합니다. 값을 반환하는 sample, sampleStream를 실행하는 시점에서 내부 동작은 모두 Lazy하고 모든 연산이 실행됩니다.

    Validation 실패 원인을 로깅하기 위해 같은 ArbitraryValue 객체들은 violations를 공유합니다. 동시에 실행하는 경우는 거이 없겠지만, 있을 수도 있으므로 ConcurrentHashMap을 구현체로 사용합니다. 공유하더라도 Validation 실패하는 경우이므로 문제가 없습니다.

    opened by seongahjo 5
  • Refactor InnerSpec

    Refactor InnerSpec

    Summary

    Refactors InnerSpec

    (Optional): Description

    InnerSpec no longer depends on ArbitraryTraverser and ManipulateOptions. MonkeyManipulatorFactory now has the responsibility to create NodeManipulators.

    How Has This Been Tested?

    opened by SooKim1110 4
  • Figure out why generating empty container in key

    Figure out why generating empty container in key

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

    Map<Map<String, String>, String>> 처럼 key 값이 컨테이너인 경우 생성할 때 반복적으로 size가 0인 경우가 발생한다. size가 0이 되어 중복된 키가 발생하여 객체 생성에 실패하게 된다. 원인을 조사하고 정리한다.

    bug 
    opened by seongahjo 4
  • Fix vulnerabilities of dependencies

    Fix vulnerabilities of dependencies

    fixture monkey 에서 사용 중인 dependency 중 보안취약점 이슈가 있는 버전을 해결된 버전으로 업데이트합니다.

    gradle 프로젝트에 dependency 를 추가 시 아래와 같이 fixture monkey 에서 사용 중인 dependency 의 보안취약점에 대해 알림을 주고 있습니다.

    스크린샷 2022-08-29 오후 5 16 48

    opened by ByungjunYou 4
  • Use explicit value types

    Use explicit value types

    This changes the Any? types of the value parameters to the generic types(V) to limit types.


    KProperty, KFunction ambiguity 를 보다가 눈에 띄어 바꿔보았습니다. 아래 그림과 같이 Any? 타입이 아니라 KProperty1의 타입으로 value 타임을 제한할 수 있는 것을 볼 수 있습니다. 컴파일에서는 breaking 이 없겠지만, breaking change에 해당합니다.

    Screen Shot 2022-07-14 at 4 05 27 PM
    opened by jwChung 4
  • Randomly apply manipulator when applying manipulator with limit

    Randomly apply manipulator when applying manipulator with limit

    ArbitraryNodes found by expression has fixed ordering. So applying manipulator with parameter limit, which parameter used as limiting the number of applied ArbitraryNode, always returns same applied ArbitraryNode. It is not an intuitive result.

    In short, this issue is to shuffle all ArbitraryNodes found by ArbitraryExpression.


    적용 회수를 입력받는 연산 (limit 을 입력받는 연산)에서 조회한 노드 순서대로 적용하는 게 아니라 랜덤하게 적용하도록 수정합니다.

    good first issue help wanted 
    opened by seongahjo 4
  • Add JoinableExpressionGenerator interface

    Add JoinableExpressionGenerator interface

    Summary

    Add JoinableExpressionGenerator for Exp

    (Optional): Description

    Removing class Exp, ExpList Splitting ExpressionGenerators into ExpressionGeneratorExtensions and ExpressionGenerators for better readability

    opened by seongahjo 0
  • JacksonArbitraryIntrospector used instead of FieldReflectionArbitraryIntrospector

    JacksonArbitraryIntrospector used instead of FieldReflectionArbitraryIntrospector

    Describe the bug

    If I set a field to use the JacksonArbitraryIntrospector all the field fields will now use the JacksonArbitraryIntrospector instead the default one.

    Your environment

    Java 17

    FixtureMonkey - 0.4.10

    Steps to reproduce

    Run invalidIntrospector on https://github.com/esfomeado/fixture-monkey-bug/blob/f5ca2c55e543a04cab279245fddfe6b946f59e5a/src/test/java/com/example/bug/FixtureMonkeyTest.java

    Expected behaviour

    Should generate the class correctly.

    Actual behaviour

    Class not generated.

    Cannot construct instance ofcom.example.bug.Condition(no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

    bug 
    opened by esfomeado 0
  • Cannot invoke

    Cannot invoke "net.jqwik.api.Arbitrary.asGeneric()" because "this.arbitrary" is null

    Describe the bug

    Cannot invoke "net.jqwik.api.Arbitrary.asGeneric()" because "this.arbitrary" is null

    Your environment

    Java 17

    FixtureMonkey - 0.4.10

    Steps to reproduce

    Run abstractTest().

    https://github.com/esfomeado/fixture-monkey-bug/blob/master/src/test/java/com/example/bug/FixtureMonkeyTest.java

    Expected behaviour

    The test should pass.

    Actual behaviour

    I get this exception:

    Cannot invoke "net.jqwik.api.Arbitrary.asGeneric()" because "this.arbitrary" is null

    bug 
    opened by esfomeado 0
  • Cannot set field

    Cannot set field

    Describe the bug

    When setting a field where the parent is an abstract class and the parent of the parent is also an abstract class it throws an error saying No resolved property is found.

    Your environment

    Java 17

    FixtureMonkey - 0.4.10

    Steps to reproduce

    Run abstractTest().

    https://github.com/esfomeado/fixture-monkey-bug/blob/master/src/test/java/com/example/bug/FixtureMonkeyTest.java

    Expected behaviour

    Should set the field correctly.

    Actual behaviour

    Throws error message saying No resolved property is found.

    bug 
    opened by esfomeado 4
  • Integration with Mockito

    Integration with Mockito

    Please comment any features you had been impressed in Mockito, check it out if they could be supported by Fixture Monkey. We'd like to make Fixture Monkey more friendly to Mockito users by improving fixture-monkey-mockito module

    help wanted 
    opened by seongahjo 0
Releases(0.4.10)
  • 0.4.10(Dec 31, 2022)

  • 0.4.9(Dec 12, 2022)

  • 0.4.8(Dec 6, 2022)

    0.4.8

    • Add set compatible for ExpressionSpec
    • Add noArgsConstructor compatible for ConstructorPropertiesIntrospector
    • Deprecate FactoryMethodArbitraryIntrospector
    • Fix PropertyDescriptorProperty not generating only getter or setter
    • Add more innerSpec support methods
    Source code(tar.gz)
    Source code(zip)
  • 0.4.7(Nov 28, 2022)

  • 0.4.6(Nov 22, 2022)

  • 0.4.5(Nov 16, 2022)

  • 0.4.4(Nov 12, 2022)

  • 0.4.3(Nov 11, 2022)

    0.4.3

    LabMonkey

    • Fix not generating over number type’s min value and max value
    • No generic container is now could be generated by LabMonkey
    • JsonNode is now could be generated by LabMonkey
    • Fix not working when adding @Pattern and @NotBlank
    • Add fixture-monkey-starter-kotlin module
    • Refactor generating unique element in Map, Set for better performance
    • Fix not getting parent’s fields inKotlin plugin

    FixtureMonkey

    • Fix propertyNameResolver not working when changing generator
    Source code(tar.gz)
    Source code(zip)
  • 0.4.2(Nov 3, 2022)

    0.4.2

    • Adding ConstructorPropertiesArbitraryIntrospector
    • Adding FactoryMethodIntrospector
    • Fix nullableContainer option
    • Adding setInner, setLazy Exp

    0.4.1

    • Fix parent type registered setNull not works if child type is registered
    • Fix not generating Java type such as, BigDecimal, UUID
    • Fix not generating Java type if adding KotlinPlugin

    0.4.0

    • Adding Exp
    • Adding setInner for manipulating Map
    • Altering all of options
    Source code(tar.gz)
    Source code(zip)
  • 0.3.5(Jun 21, 2022)

    What's Changed

    • Fix NullPointerException when using IterableSpec any()
    • Fix returns null when fixed after setNull root 0.3.0

    Full Changelog: https://github.com/naver/fixture-monkey/compare/0.3.4...0.3.5

    Source code(tar.gz)
    Source code(zip)
  • 0.3.4(May 16, 2022)

    What's Changed

    • Fix Arbitrary generation fail when using a class without package (for JDK 8)
    • Add a method to set value lazily with lambda which determines value when sample() is called

    Full Changelog: https://github.com/naver/fixture-monkey/compare/0.3.3...0.3.4

    Source code(tar.gz)
    Source code(zip)
  • 0.3.3(Mar 22, 2022)

    What's Changed

    • Refactor wildcard to generic type for removing warning
    • Fix OOM when annotated size without max

    Full Changelog: https://github.com/naver/fixture-monkey/compare/0.3.2...0.3.3

    Source code(tar.gz)
    Source code(zip)
  • 0.3.2(Jan 10, 2022)

    What's Changed

    • Add Set ExpressionSpec
    • Add Queue Builder for generating Container Queue

    Full Changelog: https://github.com/naver/fixture-monkey/compare/0.3.1...0.3.2

    Source code(tar.gz)
    Source code(zip)
  • 0.3.1(Oct 8, 2021)

    Changes

    • Add Fixture Monkey Starter module
    • Fix ArbitraryBuilder generated Arbitrary not validated by validator
    • Fix not copy valid only
    • Remove useless testing validator debug log

    Full Changelog here

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Oct 1, 2021)

  • 0.3.0-RC4(Sep 23, 2021)

  • 0.3.0-RC1(Sep 9, 2021)

JUnit 5 Parameterized Test Yaml Test Data Source

Yamaledt — JUnit 5 Parameterized Tests Using Yaml and Jamal Introduction and usage Note This is the latest development documentation. This is a SNAPSH

Peter Verhas 4 Mar 23, 2022
Utility to automatically manage all web element waits and enables to write wait-free selenium tests.

selenium-auto-wait selenium-auto-wait automatically manages all weblement waits and makes you to write wait free selenium tests. Features Waits till e

Sudharsan Selvaraj 31 Nov 1, 2022
All prs are automatically merged - star the mod to become a collaborator

community-mod is now archived. thank you to everyone to contributed to this masterpiece. The Community Mod A Mod by The Community for the Community! M

null 66 Nov 25, 2022
Test Automation Made Simple

Karate Test Automation Made Simple. Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automat

Intuit 6.5k Dec 28, 2022
Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.

That feeling you get when you know you can trust your tests Serenity BDD is a library designed to make writing automated acceptance tests easier, and

Serenity BDD 654 Dec 28, 2022
A library for setting up Java objects as test data.

Beanmother Beanmother helps to create various objects, simple and complex, super easily with fixtures for testing. It encourages developers to write m

Jaehyun Shin 113 Nov 7, 2022
A Java architecture test library, to specify and assert architecture rules in plain Java

ArchUnit is a free, simple and extensible library for checking the architecture of your Java code. That is, ArchUnit can check dependencies between pa

TNG Technology Consulting GmbH 2.5k Jan 2, 2023
Test if a request/response matches a given raml definition

raml-tester Test if a request/response matches a given raml definition. Versioning Version Contents 0.8.x Stable version, uses RAML parser 0.8.x and s

Stefan Niederhauser 71 Mar 21, 2022
PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

Writing unit tests can be hard and sometimes good design has to be sacrificed for the sole purpose of testability. Often testability corresponds to go

PowerMock 3.9k Dec 28, 2022
FitNesse -- The Acceptance Test Wiki

FitNesse Welcome to FitNesse, the fully integrated stand-alone acceptance testing framework and wiki. To get started, check out http://fitnesse.org! Q

Robert C. Martin 1.9k Jan 3, 2023
PowerMock is a Java framework that allows you to unit test code normally regarded as untestable.

Writing unit tests can be hard and sometimes good design has to be sacrificed for the sole purpose of testability. Often testability corresponds to go

PowerMock 3.9k Dec 28, 2022
Enabling Test Automation in Java

SeLion Enabling Test Automation in Java SeLion builds on top of TestNG and Selenium to provide a set of capabilities that get you up and running with

PayPal 268 Dec 11, 2022
Arbitrary test data generator for parameterized tests in Java inspired by AutoFixture.

AutoParams AutoParams is an arbitrary test data generator for parameterized tests in Java inspired by AutoFixture. Sometimes setting all the test data

null 260 Jan 2, 2023
A simple yet powerful parameterized test runner for Java.

TestParameterInjector Introduction TestParameterInjector is a JUnit4 test runner that runs its test methods for different combinations of field/parame

Google 324 Dec 30, 2022
Extensions/Plugins for JVM test frameworks

Jexter Extensions/Plugins for JVM test frameworks (JUnit 4, JUnit 5, ...) Get Jexter Binaries are available from Maven Central. Group Artifact Latest

Thundra 20 Jul 26, 2022
Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java

Scott Test Reporter for Maven and Gradle Get extremely detailed failure messages for your tests without assertion libraries, additional configuration

Dávid Csákvári 133 Nov 17, 2022
A BDD-style test runner for Java 8. Inspired by Jasmine, RSpec, and Cucumber.

Spectrum A colorful BDD-style test runner for Java Spectrum is inspired by the behavior-driven testing frameworks Jasmine and RSpec, bringing their ex

Greg Haskins 143 Nov 22, 2022
Gatling is a load test tool. It officially supports HTTP, WebSocket, Server-Sent-Events and JMS.

Gatling What is Gatling ? Gatling is a load test tool. It officially supports HTTP, WebSocket, Server-Sent-Events and JMS. Motivation Finding fancy GU

Gatling 5.8k Dec 27, 2022