Skip to content

JUnit test runner for dynamically generated tests

jessepys/junit-test-factory

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JUnit test factory runner

Download Build Status Coverage Status

Simple JUnit runner allowing you to dynamically generate tests with human readable names. This can be pretty convenient for adding customer generated test data into your test suites.

Btw, as far as I can tell, doing these things will be easier with JUnit 5.

Teaser

package com.github.kimble;

import org.junit.runner.RunWith;

import java.util.function.BiConsumer;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

@RunWith(TestFactoryRunner.class)
public class TestFactoryRunnerTest implements TestFactory {

    @Override
    public void produceTests(BiConsumer<String, GeneratedTest> sink) {
        for (int i=0; i<10; i++) {
            final int number = i;
            final String name = String.format("Test %d", number);

            sink.accept(name, () -> {
                System.out.println("This is test #" + number);
            });
        }
    }

}

Gradle test report

Dynamically generated tests shows up as expected in html reports generated by Gradle.

Gradle test report

Intellij test runner

The same is true for Intellij, although you will not be able to re-run / debug a single test as you're used to.

Intellij test runner

About

JUnit test runner for dynamically generated tests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%