-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does gotestsum support adding properties to test cases in the junit xml result file ? #311
Comments
Hello! There is currently no way to do that with What kind of data do you want to associate with the test case? Is it data that How will these properties be consumed? Is there another system that will read these properties? XSLT is a tool that could be used to modify the junit.xml document and add those properties. I haven't used XSLT in many years, and never with Go, but I think it would be possible to write something using XSLT to add those properties after the file is created. |
@dnephin Thanks for replying to my question. The data being added to the report would come from another source. We are currently integrating our Test Automation Suite results with TestRail by including a TestId in the name and parsing it out of the name attribute in the report. It would be nice to do something similar to this, where the identifier is included in the report as a testcase property: <testsuites name="test suites root">
<testsuite failures="0" errors="0" skipped="1" tests="1" time="3049" name="tests.LoginTests">
<testcase classname="tests.LoginTests" name="test_case_1" time="650">
<properties>
<property name="test_id" value="C123"/>
</properties>
</testcase>
</testsuite>
</testsuites> |
Thanks for the explanation! I'd be happy to explore some options for solving this problem. I think the few things we need to figure out are:
I've got some initial thoughts, but I'm hoping we'll find other options too. Where does the Two options that come to mind:
What do you think of these options? Is there a better way to communicate this metadata? I think the other two problems will largely depend on how we solve this first one. |
|
That's an interesting idea! The XML file is generated at the end of execution. The challenge is in how the tests are run. The processes involved look something like this: flowchart LR
gotestsum -->|run| gotest["go test"]
gotest -->|build| binary["pkg.test"]
gotest -->|run| binary
binary -.->|text output| gotest
gotest -.->|json output| gotestsum
It is also technically possible that we could call the These are roughly the two options I mentioned at the end of #311 (comment)
From the test suite side a test setup or teardown method could definitely work with both of these options. Either to print the test_id to stdout, or to write it to a file. Does a test named So far I'm thinking that the file approach would be easier. It should be easier to discover the feature, and less likely to cause problems for existing test suites. Your test suite would write out a line delimited JSON file, one line per test. TestMain can be used to write the file to disk right before the test program exits. The file format would look something like this:
You would run |
@dnephin This sounds great, thanks for writing out the flow diagram. I think you are right, given what you have already mentioned, an external metadata file would be the best approach. Can we have the JunitXMLProperties be an array of json objects that are just {"name": "value"}, instead of actually including the xml tags ? |
That is definitely possible. I like the idea of accepting XML tags because I'm not sure what other systems might expect for the xml tags and attributes. Accepting XML would allow this feature to be used by other systems, but definitely does put more of a burden on the user to ensure they are producing valid XML. Maybe the library that is responsible for creating this file could take on the responsibility of ensuring valid XML is written to the file? Are there other problems with this approach that I've missed? |
No, I think this is great, and appreciate you taking the time to respond and comment on this enhancement. Please let me know if you need anything else from me. I would be happy to help test this enhancement when it becomes available. |
There is a Go proposal open (golang/go#43936) to Allow Go Tests to Pass Metadata. If this is accepted this would be a great solution to the problem. The test suite could write the metadata, and |
Hello,
I was wondering if there was a way to add properties to a test case and be available in the xml result file.
<testcase classname="tests.LoginTests" name="test_case_1" time="650"> <properties> <property name="property1" value="value1"/> </properties>
The text was updated successfully, but these errors were encountered: