This is a simple DSL builder for writing parametrized tests in JUnit 5 using @TestFactory
Add this dependency into your application’s build.gradle
script with the latest version of the library):
plugins {
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'builders.dsl:expectations:1.0.0'
}
Or add the following dependency to your Maven project:
<dependency>
<groupId>builders.dsl</groupId>
<artifactId>expectations</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
To create a parametrized test using Expectations DSL builder, you need to create a test method returning Expectations
and annotate it with @TestFactory
annotation.
@TestFactory // (1)
Expectations basicTest3Fluent() { // (2)
Calculator calculator = new Calculator();
return given("a", "b", "c") // (3)
.are(2, 3, 5) // (4)
.and(3, 5, 8)
.and(4, 7, 11)
.expect(
"#a + #b = #c", // (5)
(a, b, c) -> calculator.add(a, b) == c // (6)
);
}
-
Annotate method with
@TestFactory
-
Make the method return
Expectations
-
Define the parameters' headers using
given
-
Define at least one data row using
are
-
Define the test title template using the headers preceded by
#
to define the placeholders -
Define the test
See the Full Documentation foe more information.