-
Notifications
You must be signed in to change notification settings - Fork 797
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
Add outgoing metadata to TestContext #2457
Comments
@bradwilson Any news on this issue? So desperately want to report out screenshots! Thanks for the hard work. |
@HoraceBury It's on the v3 roadmap. It will be part of v3, but has not been implemented yet. No other information is available at this time. |
Hey! What's up with this one? I would love to add some screenshots to my test reports. |
OK, I'm digging into this item in my brain just a little bit just out of curiosity. Please excuse my ignorance. Some questions:
|
I don't think that's sufficient, though, because if someone just writes a file to a disk, how do you translate that into a durable URI?
I don't think so, because this is more like traits than diagnostic messages. If the user wants to report something which is a formatted string, they can just use
The discussion here for XML is the reporting format that already exists. What would show up to the runners would likely just be a |
This has been implemented as "attachments", which can come in two forms: plain text strings or binary data ( This is available in v3 Adding attachmentsAdding attachments is done via two overloaded Add a plain-text string value: xunit/src/xunit.v3.core/TestContext.cs Lines 221 to 228 in cbee584
Add a binary value w/ media type: xunit/src/xunit.v3.core/TestContext.cs Lines 245 to 260 in cbee584
Attachments can only be added in the context of an executing test, which means effectively during:
During the last two steps marked with (*), you will have access to the proposed result state of the test, via Attachments recorded during the test will be available to runners via xunit/src/xunit.v3.common/Abstractions/Messages/ITestFinished.cs Lines 10 to 16 in cbee584
Updated native XML reportsThe native XML output format has been expanded to record the attachments: xunit/src/xunit.v3.runner.common/Sinks/ExecutionSink.cs Lines 444 to 472 in cbee584
This manifests in slightly different form for string values: <attachments>
<attachment name="NAME">STRING_VALUE</attachment>
</attachments> vs. binary values: <attachments>
<attachment name="NAME" media-type="MEDIA_TYPE">BASE64_ENCODED_BYTES</attachment>
</attachments> Updated JUnit XML reportsThe JUnit XML output format does not have official support for attachments, but the common pattern is to add them to the Updated XSL-T template: xunit/src/xunit.v3.runner.common/Transforms/templates/JUnitXml.xslt Lines 92 to 103 in cbee584
String values: <properties>
<property name="attachment:NAME" value="STRING_VALUE" />
</properties> vs. binary values: <properties>
<property name="attachment:NAME" value="data:MEDIA_TYPE;base64,BASE64_ENCODED_BYTES" />
</properties> Updated CTRF JSON reportsThere is no official CTRF JSON support for attachments, so we have added them to the xunit/src/xunit.v3.runner.common/Transforms/TransformFactory.cs Lines 385 to 399 in cbee584
String values: {
"attachments": {
"NAME": "STRING_VALUE"
}
} vs. binary values: {
"attachments": {
"NAME": {
"media-type": "MEDIA_TYPE",
"value": "BASE64_ENCODED_BYTES"
}
}
} |
Sample images posted to our Mastodon account: Source: Native XML: JUnit XML: CTRF JSON: |
What am I doing wrong in here ? I would expect to see attachment in VS Test Explorer with the zip file, but there is nothing to see. And another question. How can I retrieve an XML test results file that was sent in previous comment ? |
Now that v3 has a
TestContext
object, we should provide a way for test authors (and extensibility authors who are writing test extensions) a way to record additional information that can be reported (which I'll call "outgoing metadata").One example of such a request is UI-based testing systems which would like to attach screenshots to failed test records.
Let's assume a model that is like traits (aka "incoming metadata"): introduce name/value pairs of
string
=>string
, where the data is then added to the "results" object model, which then in turn gets placed into XML on the way out for reporting (this XML can be written directly to disk, and is also the basis of our transformation system to produce other report files, like competing/compatible XML report files and an HTML-based report).I believe the use of strings here rather than arbitrary types (i.e.,
string
=>object
) places a reasonable limit on the outgoing data to be able to ensure that it is serializable; using arbitrary objects then places an additional serialization burden on the end user, and at the end of the day, still needs to get translated into a string to be placed into XML. The usefulness of a Base64 encoding of a .NET binary serialized object is effectively zero; forcing the user to think about how to make a string value useful, therefore, ensures that this design consideration is not overlooked. It makes more sense, then, to just usestring
as the value type in the key/value pair, rather thanobject
+ yet another arbitrary serialization system.What remains, then, is the decision about how much we should expect from the end user about the string values, and whether we should attempt to suggest or enforce some restrictions. For example, should they be limited in size? Should we suggest or mandate that they be human readable? If we don't mandate human readability and/or limit the size, does that mean we shouldn't render their values into the HTML report, which is intended to be relatively compact and human readable?
In the aforementioned example of screenshots, I feel a bit torn by this requirement and how best to support it (indirectly).
There are two obvious (and perhaps other non-obvious) implementations here.
Option 1 is more readable in report form, but has an inherent external dependency (the file on disk) that may not have been preserved in some circumstances, like a continuous integration environment. Option 2 is not reasonable readable in a generic report, and would require some additional transformation during display that would not necessarily be inherent in the built-in HTML reporting.
As such, I'm looking for feedback on the design of this outgoing metadata system. I like the self-contained nature of the XML, and am concerned that introducing the extra concept of files necessarily complicates that model. If we directly support files, what's the best way to represent this? Perhaps the outgoing metadata is a trio of information ("key", "value", and "value-data-type") which can be used to help reports determine what to do with that information? Do we also need to provide an arbitrary external storage mechanism for values, or should we assume that specific value types are actually just Base64-encoded binary values?
The text was updated successfully, but these errors were encountered: