Annotation Type TestFactory


  • @Target({ANNOTATION_TYPE,METHOD})
    @Retention(RUNTIME)
    @Documented
    @API(status=EXPERIMENTAL,
         since="5.0")
    @Testable
    public @interface TestFactory
    @TestFactory is used to signal that the annotated method is a test factory method.

    In contrast to @Test methods, a test factory is not itself a test case but rather a factory for test cases.

    @TestFactory methods must not be private or static and must return a Stream, Collection, Iterable, Iterator, or array of DynamicNode instances. Supported subclasses of DynamicNode include DynamicContainer and DynamicTest. Dynamic tests will be executed lazily, enabling dynamic and even non-deterministic generation of test cases.

    Any Stream returned by a @TestFactory will be properly closed by calling stream.close(), making it safe to use a resource such as Files.lines() as the initial source of the stream.

    @TestFactory methods may optionally declare parameters to be resolved by ParameterResolvers.

    Since:
    5.0
    See Also:
    Test, DynamicNode, DynamicTest, DynamicContainer