spockito

Java JUnit runner for parameterized tests where the test cases are defined in a table-like manner.

License

License

Categories

Categories

Spock Application Testing & Monitoring
GroupId

GroupId

org.tools4j
ArtifactId

ArtifactId

tools4j-spockito
Last Version

Last Version

1.6
Release Date

Release Date

Type

Type

jar
Description

Description

spockito
Java JUnit runner for parameterized tests where the test cases are defined in a table-like manner.
Project URL

Project URL

http://spockito.tools4j.org
Source Code Management

Source Code Management

https://github.com/tools4j/spockito.git

Download tools4j-spockito

How to add to project

<!-- https://jarcasting.com/artifacts/org.tools4j/tools4j-spockito/ -->
<dependency>
    <groupId>org.tools4j</groupId>
    <artifactId>tools4j-spockito</artifactId>
    <version>1.6</version>
</dependency>
// https://jarcasting.com/artifacts/org.tools4j/tools4j-spockito/
implementation 'org.tools4j:tools4j-spockito:1.6'
// https://jarcasting.com/artifacts/org.tools4j/tools4j-spockito/
implementation ("org.tools4j:tools4j-spockito:1.6")
'org.tools4j:tools4j-spockito:jar:1.6'
<dependency org="org.tools4j" name="tools4j-spockito" rev="1.6">
  <artifact name="tools4j-spockito" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.tools4j', module='tools4j-spockito', version='1.6')
)
libraryDependencies += "org.tools4j" % "tools4j-spockito" % "1.6"
[org.tools4j/tools4j-spockito "1.6"]

Dependencies

compile (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Build Status Coverage Status Maven Central

spockito

Simple Java library to define data in a table-like manner. The library also provides a Junit 5 @TableSource annotation to define arguments for parameterized tests in a simple table structure. The SpockitoExtension can be used to automatically propagate fields in a test class with table data.

We also support parameterized test data in table format for Junit 4 tests through the classic Spockito test runner (see here for more information and examples for spockito with Junit 4).

Parameterized tests with @TableSource

Arguments for parameterized tests can be defined via @TableSource annotation as follows:

public class TableSourceTest {

    @TableSource({
            "| Last Name | First Name |",
            "| Jones     | David      |",
            "| Jensen    | Astrid     |"
    })
    @ParameterizedTest(name = "[{index}] {1} {0}")
    public void testUnrollNames(String lastName, String firstName) {
        assertTrue(lastName.startsWith("J"), "Last Name should start with J");
        assertTrue(firstName.endsWith("id"), "First Name should end with id");
    }

    @TableSource({
            "| Name  | Year | Birthday   |",
            "|-------|------|------------|",
            "| Henry | 1981 | 1981-11-28 |",
            "| Jessy | 1965 | 1965-03-28 |"
    })
    @ParameterizedTest(name = "[{index}] {0}")
    public void testUnrollBirthdays(String name, int year, LocalDate birthday) {
        assertEquals(5, name.length(), "Name should have 5 characters");
        assertTrue(1990 > year, "Year is before 1990");
        assertEquals(28, birthday.getDayOfMonth(), "Day is 28th");
        assertEquals(year, birthday.getYear(), "Year is consistent with birthday");
    }

    @TableSource({
            "| Name  | Year | Birthday   |",
            "|-------|------|------------|",
            "| Henry | 1981 | 1981-11-28 |",
            "| Jessy | 1965 | 1965-03-28 |"
    })
    @ParameterizedTest(name = "[{index}] {0}")
    public void testUnrollNameAndYearOnly(String name, int year) {
        assertEquals(5, name.length(), "Name should have 5 characters");
        assertTrue(1990 > year, "Year is before 1990");
    }

    @TableSource({
            "| Object   | Vertices | Angle sum |",
            "|==========|==========|===========|",
            "| Triangle |     3    |    180    |",
            "| Square   |     4    |    360    |",
            "| Pentagon |     5    |    540    |",
            "|----------|----------|-----------|",
    })
    @ParameterizedTest(name = "{2}: ({1}-2)*180 = {0}")
    public void testUnrollAngularSums(@Column("Vertices") int n,
                                      @Column("Angle sum") int degrees,
                                      @Column("Object") String name) {
        assertTrue(3 <= n, "There should be 3 or more vertices");
        assertEquals(degrees, (n-2)*180, "Angular sum is wrong for: " + name);
    }
}

This and other examples can be found here.

Run above test in IDE (here: IntelliJ)

spockito-junit5-idea-testrun.png

This and other examples can be found here.

Maven

Add the following dependency to your maven pom.xml file:

<dependency>
   <groupId>org.tools4j</groupId>
   <artifactId>spockito-junit5</artifactId>
   <version>2.0</version>
   <scope>test</scope>
</dependency>

Download

Sources and binaries can be downloaded from maven central:

FAQ

More Information

org.tools4j
tools4j.org is a collection of Java libraries and tools.

Versions

Version
1.6
1.5
1.4
1.3
1.2
1.1
1.0.0