feat: Add --output flag for JSONformatted test results
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
- Add --output flag to cmd/test.go with choices: text (default), json
- Define a TestResultJSON struct in a new or existing output package to mirror the test result fields.
- 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
- Ensure JSON output includes key fields: testResultID, success, inProgress, serviceRef, testEndpoint, runnerType, timestamp
- Consider creating a shared output formatter package (pkg/output/) to avoid code duplication if other commands need similar functionality
@lbroudoux @Harsh4902 , how this sounds to you, if good i can a raise a pr
@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.
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
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 flagwould 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-filecan 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.
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:
- text (default, current behavior)
- json (structured JSON to stdout)
- 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?
@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.
@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.
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
@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.