Skip to content
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

Clearly separate Tests from Production Code (improved setup) #109

Closed
letsdev opened this issue Jan 31, 2012 · 6 comments
Closed

Clearly separate Tests from Production Code (improved setup) #109

letsdev opened this issue Jan 31, 2012 · 6 comments

Comments

@letsdev
Copy link

letsdev commented Jan 31, 2012

Hi,

I better liked to create a IntegrationTestAppDelegate that inherits from my apps delegate and add looks somewhat like this instead of putting that stuff into my production codes app delegate:

#import "IntegrationTestsAppDelegate.h"
#import "MyTestController.h"

@implementation IntegrationTestsAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [super application:application didFinishLaunchingWithOptions:launchOptions];

    [[MyTestController sharedInstance] startTestingWithCompletionBlock:^{
        // Exit after the tests complete so that CI knows we're done
        exit([[MyTestController sharedInstance] failureCount]);
    }]; 

    return YES;
}

@end

Doing it this way has the following advantages:

  • Clean separation of the actual apps target and the integration tests target
  • No need for the additional Preprocessor Macro RUN_KIF_TESTS

Disadvantages:

  • You also need to implement a separate main for the Integration Tests that could look like this:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "IntegrationTestsAppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([IntegrationTestsAppDelegate class]));
    }
}

I personally like this variant better for the sake of the complete separation between tests and production code.

What do you think?

@implementation
Copy link

Wat?

Why do you mention me?!?!?!
Why don't you mention @octodog for example?!

31.01.12 15:03, letsdev пишет:

Hi,

I found it much easier to create a IntegrationTestAppDelegate that inherits from my apps delegate and add something like this:

#import "IntegrationTestsAppDelegate.h"
#import "MyTestController.h"

@implementation IntegrationTestsAppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [super application:application didFinishLaunchingWithOptions:launchOptions];

    [[MyTestController sharedInstance] startTestingWithCompletionBlock:^{
    // Exit after the tests complete so that CI knows we're done
    exit([[MyTestController sharedInstance] failureCount]);
    }];

    return YES;
    }

@EnD

Doing it this way has the following advantages:

  • Clean separation of the actual apps target and the integration tests target
  • No need for the additional Preprocessor Macro RUN_KIF_TESTS

Disadvantages:

  • You also need to implement a separate main for the Integration Tests that could look like this:
    #import<UIKit/UIKit.h>
    #import<Foundation/Foundation.h>
    #import "IntegrationTestsAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([IntegrationTestsAppDelegate class]));
}
}

I clearly like this variant better for the sake of the complete separation between tests and production code.

What do you think?


Reply to this email directly or view it on GitHub:
#109

@octodog
Copy link

octodog commented Jan 31, 2012

Wat?

31.01.12 15:05, implementation пишет:

Wat?

Why do you mention me?!?!?!
Why don't you mention @octodog for example?!

31.01.12 15:03, letsdev пишет:

Hi,

I found it much easier to create a IntegrationTestAppDelegate that inherits from my apps delegate and add something like this:

#import "IntegrationTestsAppDelegate.h"
#import "MyTestController.h"

@implementation IntegrationTestsAppDelegate

  • (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [super application:application didFinishLaunchingWithOptions:launchOptions];

    [[MyTestController sharedInstance] startTestingWithCompletionBlock:^{
    // Exit after the tests complete so that CI knows we're done
    exit([[MyTestController sharedInstance] failureCount]);
    }];

    return YES;
    }

@EnD

Doing it this way has the following advantages:

  • Clean separation of the actual apps target and the integration tests target
  • No need for the additional Preprocessor Macro RUN_KIF_TESTS

Disadvantages:

  • You also need to implement a separate main for the Integration Tests that could look like this:
    #import<UIKit/UIKit.h>
    #import<Foundation/Foundation.h>
    #import "IntegrationTestsAppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([IntegrationTestsAppDelegate class]));
}
}

I clearly like this variant better for the sake of the complete separation between tests and production code.

What do you think?


Reply to this email directly or view it on GitHub:

#109

Reply to this email directly or view it on GitHub:
#109 (comment)

@letsdev
Copy link
Author

letsdev commented Jan 31, 2012

Wat?! I never intended to mention one of you guys. All the @ things in my post are just source code.

Very nice user name :D So you always get a mail when ANYONE on github posts objective-c code in an issue? Great :D

@octodog
Copy link

octodog commented Jan 31, 2012

It was a joke ;)
Use triple backticks to highlight code properly.

Like this

31.01.12 15:27, letsdev пишет:

Wat?! I never mentioned one of you guys. No idea what you're talking bout. All the @ things in my post are just source code.


Reply to this email directly or view it on GitHub:
#109 (comment)

@letsdev
Copy link
Author

letsdev commented Feb 1, 2012

ok: you just get messages if a stupid github noob like me posts objective-c code :)

@bnickel
Copy link
Contributor

bnickel commented Sep 11, 2013

That's a clever solution. I can't believe I never saw it before.

Anyway, this issue is out of date due to KIF not using this runner approach anymore. Closing.

@bnickel bnickel closed this as completed Sep 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants