Skip to content

feat: Add --output flag for JSONformatted test results #301

Closed

Description

@cotishq

Reason/Context

  • Currently, microcks test outputs human-readable text only. Developers running tests in CI/CD pipelines or scripts cannot programmatically parse test results without scraping/parsing text output.
  • Users can pass --output json to get structured JSON output, enabling easier integration with automation tools, CI/CD systems, and tooling that needs machine-parseable results for reporting or gating.
  • Aligns with Microcks' CI/CD story - developers should be able to get test results inline with code being tested, without requiring web UI navigation. JSON output enables IDE integration, offline validation, and GitHub Actions PR annotations.

Description

Add an --output flag to the microcks test command that allows users to select the output format. When --output json is specified, the command should output test results as structured JSON instead of human-readable text.

Expected behaviour:

  • Default behavior remains unchanged (human-readable output)
  • --output json outputs test results as JSON to stdout
  • Exit codes still reflect test success/failure
  • Non-breaking change: no impact on existing usage

Implementation ideas

  1. Add --output flag to cmd/test.go with choices: text (default), json
  2. Define a TestResultJSON struct in a new or existing output package to mirror the test result fields.
  3. Extend the test command Run function to:
    • Check the output flag value
    • If json:Marshall the result to JSON and print to stdout
    • If text: Keep existing behavior
  4. Ensure JSON output includes key fields: testResultID, success, inProgress, serviceRef, testEndpoint, runnerType, timestamp
  5. Consider creating a shared output formatter package (pkg/output/) to avoid code duplication if other commands need similar functionality

Activity

  1. cotishq commented on May 6, 2026

    @cotishq
    ContributorAuthor

    @lbroudoux @Harsh4902 , how this sounds to you, if good i can a raise a pr

  2. Harsh4902 commented on May 7, 2026

    @Harsh4902
    Member

    @cotishq Thanks for raising this issue. I remeber me and @lbroudoux had a discussion that we should add --output option for commands. But, we were not sure which kind of outputs should be shown, also can we store this output at perticular location for further usage? Think on this and let us know, we are happy to have suggestions and PR on this topic.

  3. added
    kind/feature
    go
    on May 7, 2026
  4. cotishq commented on May 7, 2026

    @cotishq
    ContributorAuthor

    Thanks @Harsh4902 for giving clarity, I've already thought through the approach - here's what I'm proposing:
    Output formats via --output flag:

    • text - default, current behavior unchanged
    • json - tructured JSON to stdout, useful for CI/CD scripting, IDE tooling, and GH Actions annotation pipelines

    I'd hold off on additional formats like JUnit XML until i see how the TestResult struct maps - would love your thought on this

    Output destination via --output-file=<path>:
    Rather than always writing to stdout, an optional --output-file flag would write results to a specified file path. This enables GH Actions artifact uploads, local file caching for IDE integrations, and cleaner script pipelines without output redirection hacks.

    i thought smthng like pr 1 covers --output=text/json + pkg/output/ shared formatter and
    --output-file can follow as pr 2 keeping scope reviewable. Happy to merge both in a single pr too,

    would love your opinion on this approach, if it looks good i can start working on this path

  5. cotishq commented on May 8, 2026

    @cotishq
    ContributorAuthor

    Thanks @Harsh4902 for giving clarity, I've already thought through the approach - here's what I'm proposing: Output formats via --output flag:

    • text - default, current behavior unchanged
    • json - tructured JSON to stdout, useful for CI/CD scripting, IDE tooling, and GH Actions annotation pipelines

    I'd hold off on additional formats like JUnit XML until i see how the TestResult struct maps - would love your thought on this

    Output destination via --output-file=<path>: Rather than always writing to stdout, an optional --output-file flag would write results to a specified file path. This enables GH Actions artifact uploads, local file caching for IDE integrations, and cleaner script pipelines without output redirection hacks.

    i thought smthng like pr 1 covers --output=text/json + pkg/output/ shared formatter and --output-file can follow as pr 2 keeping scope reviewable. Happy to merge both in a single pr too,

    would love your opinion on this approach, if it looks good i can start working on this path

    @Harsh4902 @lbroudoux i have made the changes and the pr is ready for this like i have stated above, the PR 1 is ready, should i merge or include PR 2 (output destination) in this too or i should a raise a seperate issue and pr for it. Happy to go either way or any changes you prefer in the approach stated above, just waiting for your confirmation before raising the PR.

  6. Harishrs2006 commented on May 8, 2026

    @Harishrs2006
    Contributor

    Hi @cotishq and @Harsh4902 —
    i want to flag a coordination issue before
    both PRs land separately.

    i have PR #339 open which adds --output-format=plain/github-actions to
    the test command (for issue #332). If cotishq's --output=text/json PR
    also merges, the test command will end up with two separate overlapping
    flags.

    i would suggest we unify under a single --output flag with three values:

    1. text (default, current behavior)
    2. json (structured JSON to stdout)
    3. github-actions (emits ::error:: / ::notice:: workflow annotations)

    This closes both #301 and #332 in one clean flag. I am happy to update
    PR #339 to follow this unified approach, or collaborate with @cotishq
    if they want to include github-actions in their PR instead.

    @Harsh4902 what is your preference — should we unify these?

  7. cotishq commented on May 9, 2026

    @cotishq
    ContributorAuthor

    @Harishrs2006 Thanks for flagging this. I raised #301 earlier and have been waiting for @Harsh4902 direction on the approach before opening a PR - wanted to make sure the design was confirmed first.
    The unified --output flag idea with text, json, and github-actions makes sense. @Harsh4902 happy to go whichever direction works best - I can include github-actions support in my PR, or we can coordinate. Your call on how to proceed.

  8. Harsh4902 commented on May 11, 2026

    @Harsh4902
    Member

    @cotishq @Harishrs2006 nice to see you guys are wanted to work in collaboration. I would say a you can use global --output flag and then with passing arguments you can change the type of output. This way, in future we can include more output types. And would also recommend text, json, yaml as must needed format.

  9. Harishrs2006 commented on May 11, 2026

    @Harishrs2006
    Contributor

    thanks @Harsh4902!
    should github-actions format (for ::error::/::notice:: annotations) be included alongside text, json, yaml or kept as a follow-up?

    @cotishq happy to contribute github-actions support to your PR directly to avoid duplication

  10. cotishq commented on May 11, 2026

    @cotishq
    ContributorAuthor

    @Harsh4902 got it! I'll update the implementation to include yaml alongside text and json under a global --output flag and raise the PR shortly.
    @Harishrs2006 once the base PR merges, you can add github-actions support on top - that keeps both PRs clean and reviewable separately.

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

    component/cligokind/feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions