Coder Social home page Coder Social logo

junit-easy-tools's Introduction

Download Build Status codecov Dependency Status Codacy Badge

junit-easy-tools

Extensions for JUnit4

@DataProducer

Provides lazy calculated parameters inserted to test method.

Example

Simple example

The value of stringProducer will be calculated and injected to the testMethod(String string)

@DataProducer
public static Supplier<String> stringProducer = () -> RandomStringProvider.get();

@Test
public void testMethod(String string) {
   ...
}

Example with iterations

The testMethod(String string) will run three times (@ProducedValues(iterations = 3)). Each run the value of stringProducer will be recalculated, so the new value will be provided.

@DataProducer
public static Supplier<String> stringProducer = () -> RandomStringProvider.get();

@Test
@ProducedValues(iterations = 3)
public void testMethod(String string) {
   ...
}

Named @DataProducer

To testMethod(@ProducedValue(producer = "calculated") String string) will be injected values from calculatedProducer. If no name is specified for @DataProducer, the field name will be considered as @DataProducer name.

@DataProducer
public static Supplier<String> randomProducer = () -> RandomStringProvider.get();

@DataProducer(name = "calculated")
public static Supplier<String> calculatedProducer = () -> CalculatedStringProvider.get();

@Test
public void testMethod(@ProducedValue(producer = "calculated") String string) {
   ...
}

Multiple @DataProducer of the same type

Method test(String s) will be executed twice. The first time value from random @DataProducer will be injected. The second time value from queue @DataProducer will be injected.

@DataProducer
public static Supplier<String> random = () -> RandomStringProvider.get();

@DataProducer
public static Supplier<String> queue = () -> StringQueue.next();
 
@Test
public void test(String s) {
    ...
}

Multiple @DataProducer of the same type and iterations

Method test(String s) will be executed six times. Three iterations with each @DataProducer.

@DataProducer
public static Supplier<String> random = () -> RandomStringProvider.get();

@DataProducer
public static Supplier<String> queue = () -> StringQueue.next();

@Test
@ProducedValues(iterations = 3)
public void test(String s) {
    ...
}

junit-easy-tools's People

Contributors

aldocano avatar seriybg avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

junit-easy-tools's Issues

Add feature to repeat tests that runs with JUnitDataProducer

Some annotation on the test method should make the test repeat it's execution as many time as is set it annotation parameter. Value injected to the test should be recalculate each time.
Example:

@Test
@Repeat(3)
public void testMethod(int i){
   ...
}

Bug with iterating tests run when more that one DataProducers satisfy the type

Looks like if we have two data producers of the same type, when using iteration over the tests method, only one DataProducer is used

the following code fails

    private static final Queue<String> valuesWithNulls = new LinkedList<>();

    @DataProducer
    public static Supplier<String> producerWithNulls = valuesWithNulls::poll;

    @DataProducer
    public static Supplier<String> onlyNullSupplier = () -> null;

    @Before
    public void fillValues() throws Exception {
        valuesWithNulls.add("firstString");
        valuesWithNulls.add(null);
        valuesWithNulls.add("thirdOne");
        valuesWithNulls.add(null);
    }

    @Test
    @ProducedValues(nullsAccepted = false, iterations = 4)
    public void shouldNotAcceptNulls(String value) throws Exception {
        assertThat(value).isNotNull();
    }

Extend documentation

  • Multiple @DataProducer of the same type:
@DataProducer
public static Supplier<String> first = () -> "first";

@DataProducer
public static Supplier<String> second = () -> "second";

@Test
//@ProducerValues(iterations = 2) -> in this case test method will be executed 4 time (2 times for each supplier)
public void test(String s) {
    //Will be executed twice with both provided value from first and second suppliers
}

Fix zappr config

For now zappr config matches uppercase letter with dash and letter
Fix to match: word #[digits]

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.