All Projects → JavaUnit → Autoparams

JavaUnit / Autoparams

Licence: mit
Arbitrary test data generator for parameterized tests in Java inspired by AutoFixture.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Autoparams

automock
A library for testing classes with auto mocking capabilities using jest-mock-extended
Stars: ✭ 26 (-66.23%)
Mutual labels:  unit-testing, tdd
Unit Testing Tips
Unit testing tips by examples in PHP
Stars: ✭ 318 (+312.99%)
Mutual labels:  unit-testing, tdd
respect
RSpec inspired test framework for Reason/OCaml/Bucklescript.
Stars: ✭ 28 (-63.64%)
Mutual labels:  unit-testing, tdd
SimplyVBUnit
The SimplyVBUnit framework provides powerful unit-testing capabilities for VB6.
Stars: ✭ 28 (-63.64%)
Mutual labels:  unit-testing, tdd
Jasmine Matchers
Write Beautiful Specs with Custom Matchers for Jest and Jasmine
Stars: ✭ 552 (+616.88%)
Mutual labels:  unit-testing, tdd
tdd roman csharp
Kata: TDD Arabic to Roman Numerals with C#
Stars: ✭ 14 (-81.82%)
Mutual labels:  unit-testing, tdd
Doctest
The fastest feature-rich C++11/14/17/20 single-header testing framework
Stars: ✭ 3,568 (+4533.77%)
Mutual labels:  unit-testing, tdd
doctest
The fastest feature-rich C++11/14/17/20 single-header testing framework
Stars: ✭ 4,434 (+5658.44%)
Mutual labels:  unit-testing, tdd
Ut
UT: C++20 μ(micro)/Unit Testing Framework
Stars: ✭ 507 (+558.44%)
Mutual labels:  unit-testing, tdd
Bash unit
bash unit testing enterprise edition framework for professionals
Stars: ✭ 419 (+444.16%)
Mutual labels:  unit-testing, tdd
oletus
Minimal ECMAScript Module test runner
Stars: ✭ 43 (-44.16%)
Mutual labels:  unit-testing, tdd
Enzyme Matchers
Jasmine/Jest assertions for enzyme
Stars: ✭ 881 (+1044.16%)
Mutual labels:  unit-testing, tdd
book-fullstack-react-with-typescript
Working through the code samples from Fullstack React with Typescript by Maksim Ivanov and Alex Bespoyasov
Stars: ✭ 52 (-32.47%)
Mutual labels:  unit-testing, tdd
zx-spec
A unit testing framework for Sinclair ZX Spectrum assembly
Stars: ✭ 32 (-58.44%)
Mutual labels:  unit-testing, tdd
utest
Lightweight unit testing framework for C/C++ projects. Suitable for embedded devices.
Stars: ✭ 18 (-76.62%)
Mutual labels:  unit-testing, tdd
Awesome Unit Testing Swift
A curated collection of awesome blog articles, books, talks, podcasts, tools/frameworks and examples.
Stars: ✭ 272 (+253.25%)
Mutual labels:  unit-testing, tdd
Alsatian
TypeScript testing framework with test cases
Stars: ✭ 244 (+216.88%)
Mutual labels:  unit-testing, tdd
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (-57.14%)
Mutual labels:  unit-testing, tdd
Ava
Node.js test runner that lets you develop with confidence 🚀
Stars: ✭ 19,458 (+25170.13%)
Mutual labels:  unit-testing, tdd
Quixote
CSS unit and integration testing
Stars: ✭ 788 (+923.38%)
Mutual labels:  unit-testing, tdd

AutoParams

CI Publish

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

Sometimes setting all the test data manually is very annoying. Sometimes some test data is required but not that important for a particular test. AutoParams automatically generates test arguments for your parameterized test method so you can focus more on your domain and your requirements.

AutoParams is very easy to use. Just decorate your parameterized test method with @AutoSource annotation just like using @ValueSource annotation or @CsvSource annotation. That's all. Then AutoParams wiil generate arbitrary arguments for the parameters of the test method automatically.

@ParameterizedTest
@AutoSource
void parameterizedTest(int a, int b) {
    Calculator sut = new Calculator();
    int actual = sut.add(a, b);
    assertEquals(a + b, actual);
}

In the example above, you can see that the arbitrary test data may eliminate the need for triangulation from tests.


Requirements

At least JDK1.8 or higher

Install

Maven

<dependency>
  <groupId>io.github.javaunit</groupId>
  <artifactId>autoparams</artifactId>
  <version>0.0.8</version>
</dependency>

Gradle

testImplementation 'io.github.javaunit:autoparams:0.0.8'

Features

Primitive Types

AutoParams generates arbitrary test arguments of primitive types.

@ParameterizedTest
@AutoSource
void testMethod(boolean x1, int x2, long x3, float x4, double x5) {
}

Simple Objects

AutoParams generates arbitrary simple objects for the test parameters.

@ParameterizedTest
@AutoSource
void testMethod(String x1, UUID x2) {
}

Enum Types

Enum types are also supported. AutoParams randomly selects enum values.

public enum Day {
    SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
    THURSDAY, FRIDAY, SATURDAY
}

@ParameterizedTest
@AutoSource
void testMethod(Day day) {
}

Complex Objects

AutoParams creates complex objects using a public constructor with arbitrary arguments. If the type has more than one public constructors, AutoParams chooses the constructor with the fewest parameters.

class ComplexObject {

    private final int value1;
    private final String value2;

    public ComplexObject(int value1, String value2) {
        this.value1 = value1;
        this.value2 = value2;
    }

    public int getValue1() {
        return value1;
    }

    public String getValue2() {
        return value2;
    }

}

@ParameterizedTest
@AutoSource
void testMethod(ComplexObject object) {
}

Generic Types

AutoParams creates objects of generic type using a public constructor with arbitrary arguments. If the type has more than one public constructors, AutoParams chooses the constructor with the fewest parameters.

class GenericObject<T1, T2> {

    private final T1 value1;
    private final T2 value2;

    public GenericObject(T1 value1, T2 value2) {
        this.value1 = value1;
        this.value2 = value2;
    }

    public T1 getValue1() {
        return value2;
    }

    public T2 getValue2() {
        return value3;
    }

}

@ParameterizedTest
@AutoSource
void testMethod(
    GenericObject<String, ComplexObject> object1,
    GenericObject<UUID, GenericObject<String, ComplexObject>> object2) {
}

Collection Types

AutoParams supports a variety of collection types and streams.

Arrays

AutoParams generates an array instance with three elements.

@ParameterizedTest
@AutoSource
void testMethod(int[] array1, String[] array2) {
}

List Types

List<E> interface and ArrayList<E> class supported. Generated list objects contain few elements.

@ParameterizedTest
@AutoSource
void testMethod(List<String> list, ArrayList<UUID> arrayList) {
}

Set Types

Set<E> interface and HashSet<E> class supported. Generated set objects contain few elements.

@ParameterizedTest
@AutoSource
void testMethod(Set<String> set, HashSet<UUID> hashSet) {
}

Map Interface

Map<K, V> interface and HashMap<K, V> class supported. Generated map objects contain few pairs.

@ParameterizedTest
@AutoSource
void testMethod(Map<String, ComplexObject> map, HashMap<UUID, ComplexObject> hashMap) {
}

Generic Stream Interface

AutoParams supports the generic Stream<T> interface. Generated stream objects provide few elements.

@ParameterizedTest
@AutoSource
void testMethod(Stream<ComplexObject> stream) {
}

Repeat

Unit tests can be repeated with arbitrary test data. Set repeat property of @AutoSource annotation as many times as you want to repeat.

@ParameterizedTest
@AutoSource(repeat = 10)
void testMethod(int a, int b) {
    // This test method is performed ten times.
    Calculator sut = new Calculator();
    int actual = sut.add(a, b);
    assertEquals(a + b, actual);
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].