Annotation Interface CompositeTypeGeneratorSource


@CompositeTypeGeneratorSource is an ArgumentsSource that provides access to values from multiple TypedGenerator implementations for parameterized tests, generating combinations of values.

This annotation allows you to combine multiple TypedGenerator implementations to generate combinations of values for your parameterized tests. The generators can be specified in three ways:

  • By class using generatorClasses
  • By method reference using generatorMethods
  • By generator type using generators with GeneratorType enum values

Example Usage

 
 // Using generator classes
 @ParameterizedTest
 @CompositeTypeGeneratorSource(
     generatorClasses = {
         NonBlankStringGenerator.class,
         IntegerGenerator.class
     },
     count = 3
 )
 void testWithMultipleGenerators(String text, Integer number) {
     assertNotNull(text);
     assertNotNull(number);
     // Test with combinations of text and number
 }
 
 // Using generator methods
 @ParameterizedTest
 @CompositeTypeGeneratorSource(
     generatorMethods = {
         "createStringGenerator",
         "createIntegerGenerator"
     },
     count = 3
 )
 void testWithMultipleMethodGenerators(String text, Integer number) {
     assertNotNull(text);
     assertNotNull(number);
     // Test with combinations of text and number
 }
 
 // Using generator types from the Generators class
 @ParameterizedTest
 @CompositeTypeGeneratorSource(
     generators = {
         GeneratorType.NON_EMPTY_STRINGS,
         GeneratorType.INTEGERS
     },
     count = 3
 )
 void testWithGeneratorTypes(String text, Integer number) {
     assertNotNull(text);
     assertNotNull(number);
     // Test with combinations of text and number
 }
 
 // Method generators
 static TypedGenerator<String> createStringGenerator() {
     return Generators.strings(5, 10);
 }
 
 static TypedGenerator<Integer> createIntegerGenerator() {
     return Generators.integers(1, 100);
 }
 
 
Since:
2.0
Author:
Oliver Wolff
See Also:
  • Element Details

    • generatorClasses

      The TypedGenerator classes to use for generating test values. Each class must have a no-args constructor.
      Returns:
      the TypedGenerator classes
      Default:
      {}
    • generatorMethods

      The method names to invoke to get TypedGenerator instances. Methods can be in the test class or in external classes using the format "fully.qualified.ClassName#methodName".
      Returns:
      the method names
      Default:
      {}
    • generators

      The generator types to use from Generators class. This is a convenient way to use the standard generators without having to create custom generator classes or methods.
      Returns:
      the generator types
      Default:
      {}
    • count

      int count
      Number of combinations to generate. For each generator, this many values will be generated and combined in a cartesian product with values from other generators.
      Returns:
      the number of values to generate per generator, defaults to 1
      Default:
      1
    • cartesianProduct

      Whether to generate a cartesian product of all generator values. If true, all possible combinations of values from the generators will be created. If false, generators will be paired one-to-one (requires all generators to produce the same number of values).
      Returns:
      true to generate a cartesian product, false for one-to-one pairing
      Default:
      true