[fbxctest] Streaming JSON results during test run
At the moment, fbxctest only 'streams' the JSON results at the end of the test run. This isn't a dealbreaker; you still get the full JSON report at the end of the test run. However compared to xctool, this might be considered a regression. If you are integrating fbxctest with Buck, you don't see the live updating counter as buck runs tests:
[+] TESTING...14.8s (26 PASS/0 FAIL)
Since I think fbxctest is still in alpha, I'd love to help implement the streaming JSON reporting, but I need a little direction.
I've been looking at FBJSONTestReporter.m and the general pattern seems to be 'store the dictionary into an array, and at the end of the test run iterate over that array, convert each dictionary into JSON, and print each JSON event to stdout'.
Tried to hack this into working by calling printEvent: at the end of storeEvent:, and removing the fast enumeration in printReportWithError: that prints each event, but this isn't quite correct (though it did work).
While I think I could mess with the calling order and semantics of these functions I wanted to know what way you prefer, so I don't waste time implementing this the wrong way.
I think this could take a few steps:
- Pass in a
FBFileConsumerobject in the constructor that wraps a+[FBFileWriter writerWithFileHandle:NSFileHandle.standardOut blocking:YES]. This will mean that you can unit-test theFBJSONTestReporterby injecting a different Writer and asserting based on the output. Currently this class implicitly writes tostdout, which makes it hard to test. Implement the file writing in terms of theFBFileConsumer. - Extract the creation of 'event dictionaries' to class functions that take all the inputs and return a dictionary. It looks like there is some mixing and matching going on in that class, so simply extracting the creation of these dictionaries would be a huge help.
- Replace usages of
storeEvent:withprintEvent:, this will mean they are written as they appear. This makes the assumption that all calls toFBJSONTestReporterwill be serialized (I'm not sure if this assumption is correct).
You may have to store some state inside this component as you are going along since there are messages like No end-ocunit event was received, the test bundle has likely crashed, which depends on some internal state. You could also store all the events, but print them as well. Just make sure not to duplicate them otherwise printReportWithError: will double-up the reporting.
I've landed the bulk of 2) in the steps here. I have some changes ready for 3) just need to test it a bit more and will likely land next week.
@alanzeino this is should be done as of 6bdf5f21ea16ba097523cac9e38d571c015cd30f. Assigning back to you to confirm that this satisfies what you're looking for with the fbxctest + buck interaction.
Looks good in my testing locally; I'll shadow test it on our CI for a day or two to know for sure.
Thanks!
@robbertvanginkel since you're looking at this now, anything to report back on this issue?
The streaming was reverted in 0ba924317aa2e6109331b398fb138784fb51e84c. When using fbxctest from buck, buck expects matching begin and end for every event in the json stream. With a crashing test the output would just stop and the consuming process (buck) would crash. We should be able to fix that.
However, in terms of priority there's some more significant things to handle before we could replace xctool with fbxctest from buck. Most notably fbxctest always opens and boots its own simulators, and isn't capable of running ios tests without simulator (like described in https://github.com/facebook/FBSimulatorControl/blob/master/fbxctest/Documentation/Details.md#optimisations-for-logic-tests). We rely on some of those xctool behaviours for speed internally, so we'd need to work on those too before we could use fbxctest as drop in replacement.
We just released idb. a new tool that improves significantly over fbsimctl. We recommend switching over. As part of our renewed commitment to this repo we are cleaning up old issues and will be monitoring and reviewing more closely from now on. if you still think this issue is relevant feel free to reopen