Skip to content

Latest commit

 

History

History
54 lines (43 loc) · 1.54 KB

File metadata and controls

54 lines (43 loc) · 1.54 KB

How to Use TestFactory

Contents

Explanation

Approvals uses the stack trace to figure out the name of the .approved. file. Dynamic tests require some intervention to capture this at the right time.

Because of this, you will always have to use the Options when calling verify() as well.

Java

Here is an example of how to do this in Java:

@TestFactory
Collection<DynamicTest> testFactory3()
{
  return Stream.of(1, 2).map(number -> JupiterApprovals.dynamicTest("test " + number,
      o -> Approvals.verify("content for " + number, o))).collect(Collectors.toList());
}

snippet source | anchor

Kotlin

Here is an example of how to do this in Kotlin:

@TestFactory
fun `test factory`(): List<DynamicTest> {
    return listOf(1, 2).map { it ->
        JupiterApprovals.dynamicTest("square $it") {
                o -> Approvals.verify("${it}^2 = ${it * it}", o)
        }
    }
}

anchor


Back to User Guide