Skip to content

Allow tests to notify listeners of saved files #692

Closed as not planned
Closed as not planned
@mc1arke

Description

@mc1arke

Tests that save files (screenshots, logs, data extracts etc) currently have no way of notifying external programs where these files have been saved, other than possibly by printing a line to a logger or System.out or by writing to a file that other programs are aware of. It would be nice for tests to be able to notify additional events (e.g file saved) to test listeners so that IDEs, CI servers or any other calling program can link to or load these for a user.

Kohsuke Kawaguchi did write a blog post sometime back about this: http://kohsuke.org/?s=junit+attachment which shows the hack created to allow Jenkins to attach files to test reports.

Actually implementing this is a bit of a challenge since tests don't have visibility of listeners. A couple of options I can think of for approaching this:

  1. Allow tests to have a constructor that takes aFileListener parameter for reporting file events to (with FileListener just being a wrapper round a list of TestListeners).
  2. Allow test to declare a setFileEventListener(FileListener) method, possibly from a new FileHandlingTest interface
  3. Create a FileListenerRule rule that records a list of saved files then throws a FilesSaved exception which runners pick up (similar to how ErrorCollector works).
  4. Create a special FileListenerRule rule which runners look for whilst constructing the test and inject any TestListeners into.

Out of these options, 1 and 2 seem to be reverting to JUnit3 style structures so I'm not convinced they're particularly suitable. Option 3 isn't brilliant since it's using exceptions to handle flow control for non error scenarios, wouldn't work with custom runners (failures/errors would be reports for file saves) and may cause issues with some Rules. Option 4 wouldn't report file events for any custom runners that didn't inject listeners into the rule but wouldn't cause failures in this scenario, although does require runners interact directly with a particular rule type which some people may object to.

I'm happy to create some code for the different options but want to know initial opinions about whether anyone wants this feature, and whether anyone has any strong opinions about how this should (or shouldn't) work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions