The expected usability is going to be something like this, right?
@Test
func myTest() {
let attachment = Attachment("hello world!")
attachment.attach()
}
or even
@Test
func myTest() {
Attachment("Some attached data").attach()
}
I get why, internally, the Attachment type needs to be a thing. However, this feels a little awkward to actually use. I can imagine some amount of confusion by developers not realizing that they have to call attach() in order to actually record the attachment in the test.
I think that a separate attach(...) (or createAttachment(...)?) function which essentially wraps Attachment(...).attach() would be a good idea.
Additionally, if we decide to add this function, then I don't think that the Attachment type needs to be exposed publicly, as the attach function would essentially duplicate the public functionality.
Some disclaimer: I haven't used the attachments API in XCTest much, so I might be missing some use cases here.