johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.55k stars 566 forks source link

TDD live tests support for Swift #223

Closed polac24 closed 7 years ago

polac24 commented 7 years ago

Hi, this pull-request contains a feature to automatically execute all tests covering implementation file (very useful in TDD). It works only for Swift development.

Thanks to this feature, injectionforxcode provides a great TDD developer experience, where tests are executed every time, developer saves file with ⌘+S. I found is very useful.

It contains:

Requirements This pull-request assumes that user did integrate InjectionTDD framework (https://github.com/polac24/InjectionTDD). If a developer wants to see a notification readme there shows how to add this breakpoint to Xcode.

Impact on existing cases In general, users that did not use ⌘+U (framework XCTest has not be found in log), should not observer any significant overhead (scanning even huge log is really quick, comparing to xcodebuild).

Tested and verified environment

johnno1962 commented 7 years ago

Hi Bartosz, Thanks for looking into this for me but I’m a little reluctant to make any changes to injectionforxcode at the moment as it seems to be running fine for most users and is rather brittle. I’ve added a note to the injection README pointing users to your REPO if they would like to do TDD. (P.S. it looks like you’ll need to add “InjectUnitTests.pm” to the project so it runs correctly.)

johnno1962 commented 7 years ago

On second thoughts, talking to @orta I’ll merge for now If you squash it up so I can revert easily if there are any problems. It seems to work once you fix the missing library file. Thanks for this 👍

orta commented 7 years ago

Amazing PR, I've tried to do this before and failed. Your user-land code is also much more elegant - great job.

@polac24 is it also possible that you can add some way to allow running the full test suite also? E.g. either opting in, or opting out of listening?

I'd imagine in a large codebase, you'd want to be able to provide an scheme for watch mode and a scheme for running the full tests. For example:

screen shot 2017-09-24 at 7 23 23 am
polac24 commented 7 years ago

@johnno1962, thanks for pointing out missing InjectUnitTests.pm in pbxproj. I added it and squashed PR.

@orta, it would be possible to run all the tests, but I was afraid that it can take too long to recompile all implementation and test files for the sake of running full suite of tests. Attaching all the implementation and test binaries every time into InjectionBundle is required due to static dispatch that Swift uses. Otherwise, old version of a struct/enum/extension could be used in our tests... However, we can force developers to disable "Code coverage" for this schema and then reuse all ".o" binaries directly from incremental swiftc command. Do you think that this requirement/limitation is reasonable? Thanks @orta, for your suggestion, I will definitely consider it. It totally makes sense for me!

johnno1962 commented 7 years ago

Let me know when you’re done and I’ll perform some checks. I’ll merge this evening in case you have any last minute changes. Thanks again.

polac24 commented 7 years ago

I'm done.

Thanks!

johnno1962 commented 7 years ago

Do you have an example project with a test I can clone?

polac24 commented 7 years ago

I added some samples to https://github.com/polac24/InjectionTDD/tree/master/Example

johnno1962 commented 7 years ago

OK, you’re live and I’ve rolled a new version of the Injection App including your changes available from http://johnholdsworth.com/injection.html if you want to test it out. Thanks!