Skip to content

Worth to add to documentation that @TableTest can be nicely combined with @MethodSource #30

Description

@AlexeyKuznetsov-DD

Hi!

We found that actually in case of complex params that is hard to put as string into @TableTest it is possible to use best from both worlds, see following snippet:

  @TableTest({
    "Scenario       | Input          | Expected                ",
    "null input     |                | '{}'                    ",
    "empty map      | [:]            | '{}'                    ",
    "single entry   | [key1: value1] | '{\"key1\":\"value1\"}' "
  })
  @ParameterizedTest(name = "test mapping to JSON object: {0}")
  @MethodSource("testMappingToJsonObjectArguments")
  void testMappingToJsonObject(@Scenario String scenario, Map<String, Object> input, String expected) throws IOException {
   ... some teset logic here ...
  }

  static Stream<Arguments> testMappingToJsonObjectArguments() {
    Map<String, Object> complexMap = new LinkedHashMap<>();
    complexMap.put("key1", null);
    complexMap.put("key2", new UnsupportedType());

    return Stream.of(
        arguments("complex map", complexMap, "{\"key1\":null,\"key2\":"toString\"}")
    );
  }

And all tests scenario will be executed under same name.
I think it is worth to document such case.

Activity

  1. nchaugen commented on Mar 12, 2026

    @nchaugen
    Owner

    Cool! I didn't know that was possible.

    That is a neat way to support the corner cases with input values that cannot be expressed in TableTest value syntax.

    Thanks, I will add this to the docs.

  2. AlexeyKuznetsov-DD commented on Mar 12, 2026

    @AlexeyKuznetsov-DD
    Author

    Yep, we will follow this way so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions