-
Notifications
You must be signed in to change notification settings - Fork 509
Add DSL for setup/teardown of entire test suite #427
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
Conversation
This is the bare bones required to hook into setup and teardown of an entire SenTestSuite. This is a starting point that could make way for a real DSL for Kiwi test suite configuration.
Example usage: #import <Kiwi/Kiwi.h> CONFIG_START beforeAllSpecs(^{ NSLog(@"BEFORE ALL SPECS"); }); afterAllSpecs(^{ NSLog(@"AFTER ALL SPECS"); }); CONFIG_END (Add this code to a file `<tests-dir>/Support/Config.m` and ensure it is part of your unit test bundle's Compile Sources build phase.) - - - Defines a `KWSuiteConfigurationBase` class that provides a `+defaultConfiguration` singleton instance. The first time this method is called, we look for a class named `KWSuiteConfiguration` that is a subclass of `KWSuiteConfigurationBase`, and instantiate it. This class is declared by using the `CONFIG_START` and `CONFIG_END` macros. When the default configuration receives the `-setUp` message, it sends `-configureSuite` to `self`, which executes the code between `CONFIG_START` and `CONFIG_END`. The blocks passed to `beforeAllSpecs` and `afterAllSpecs` are then executed in `-setUp` and `-tearDown`, respectively.
Extracts `+[SenTestSuite patchTestSuiteForBundlePathIMP]` into its own category defined in TestSuiteConfigurationAdditions.h, extending either `SenTestSuite` or `XCTestSuite`, depending on whether Kiwi is compiled with the `XCT_EXPORT` macro.
Removes duplication of `#ifdef XCT_EXPORT ... #endif` directives by instead providing macros that expand to the appropriate class name (e.g., `SenTestSuite` vs. `XCTestSuite`, `SenTestCase` vs. `XCTestCase`).
Here's a working example: sharplet/EnumeratorKit@0cd122b. |
Any update on this? Would be great to get some feedback. |
Yeah this would be great! The implementation looks good. |
@sharplet I've originally had a different idea of implementing this, but if it's stable enough we can merge it. Would you mind adding a functional test for it? |
Add DSL for setup/teardown of entire test suite
@sharplet thank you very much sir, merging so everybody can use the feature. Still, if you have time, some tests would be appreciated. |
@sharplet This is an amazing feature. Mad props! |
Thanks guys! 😃 Re. adding a functional test for this: I've been thinking about how I would go about testing it, and am not really sure how to proceed. For example, with the Let me know if you have any other (simpler) ideas. Also, I tried this out on one of our projects at work and unfortunately the hooks weren't executed. I haven't yet figured out what the difference was, but perhaps there are some test bundle configurations where |
@sharplet right - that's what my concern was. I've had in mind subclassing + (void)initialize {
[[NSUserDefaults standardUserDefaults] setValue:@"VATestObserver"
forKey:XCTestObserverClassKey];
[super initialize];
} More info: |
<
8000
svg aria-label="Show options" role="img" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-kebab-horizontal">
This implementation doesn't work if the test target is an application test, that is has a bundle loader and the Target in the General tab is an app. Both I've created a sample project here based on the original EnumerationKit example: https://dl.dropboxusercontent.com/u/2702446/EnumeratorKit.zip What I did was create an application target called App and changed the Specs target to use App as its target. |
Thanks for the report @fcy — I started work on a fix for application tests a little while ago, and just haven't had time to tidy it up and push it yet. @supermarin For XCTest, I think an |
Good to know 👍 Humm looks I could create a |
@sharplet I'm all down for it if implementation will be simple and XCTest only. |
👍 for supporting only XCTest FYI, I've created an
|
Reverts c811d87, 090a4ab, 253322a, and e86cc03, part of pull request kiwi-bdd#427, in favor of resolving issue kiwi-bdd#473. This removes the `CONFIG_START` and `CONFIG_END` macros in the hopes of adding them again, after further testing, at a later date.
Reverts c811d87, 090a4ab, 253322a, and e86cc03, part of pull request kiwi-bdd#427, in favor of resolving issue kiwi-bdd#473. This removes the `CONFIG_START` and `CONFIG_END` macros in the hopes of adding them again, after further testing, at a later date.
Was restored in 2.3.0 1a6a5e6 |
@sharplet I'm interested in trying to get the |
@huynguyen That's great! I'm thinking it should be possible to implement the Does that make sense? |
@sharplet yea, I'll give it a shot and open a PR when I got something. |
This should hopefully address https://github.com/allending/Kiwi/issues/266. Works for both OCUnit and XCTest.
Example usage:
(Add this code to a file
<tests-dir>/Support/Config.m
and ensure it is part of your unit test bundle's Compile Sources build phase.)I'd love to go further and add support for
beforeEachSpec
,afterEachSpec
,beforeEachExample
andafterEachExample
, however it would be great to get feedback on this API first.