GHUnit iOS Tests run in Simulator, but not via command line

638 views
Skip to first unread message

LukeFarran

unread,
Nov 14, 2012, 4:34:11 PM11/14/12
to ghu...@googlegroups.com
Hello,

I have a GHUnit iOS XCode project setup to test a framework that will be used for future iOS applications.  I am trying to setup the project with Jenkins to do automated builds to provide the test output via the JUnit XML format.  My Xcode project only has the test target. The project runs fine with the simulator and on a device, all of the tests run with the correct output.  However, when I do a 'make clean && make test' from the command line, the project builds successfully, but none of the tests are run.  Therefore, the test XML output is not generated to use with Jenkins.  For a sanity check, I ran a simple project that had a regular target and a test target and the command line output worked properly (using the following demo test app: http://www.raywenderlich.com/3716/unit-testing-in-xcode-4-quick-start-guide with the added shell scripts and MakeFile).

Does an iOS XCode project have to a separate target for the command line to work properly?  

Attached are my MakeFile and RunTests.sh files.

Any feedback is appreciated.

Thanks!

Luke

MakeFile: 

default:
#Set default make action here for the desired target
xcodebuild -target SSPTest -configuration SSPTest -sdk iphonesimulator build

clean:
-rm -rf build/*

test:
GHUNIT_CLI=1 GHUNIT_AUTORUN=1 GHUNIT_AUTOEXIT=1 WRITE_JUNIT_XML=YES JUNIT_XML_DIR=build/test-results xcodebuild -target SSPTest -configuration Debug -sdk iphonesimulator build
RunIPhoneSecurityd.sh
RunTests.sh

Joshua Moody

unread,
Nov 14, 2012, 7:36:54 PM11/14/12
to ghu...@googlegroups.com

Luke Farran

unread,
Nov 15, 2012, 3:50:30 PM11/15/12
to ghu...@googlegroups.com
Thanks for the quick response Joshua!  


On Wed, Nov 14, 2012 at 6:36 PM, Joshua Moody <joshua...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "GHUnit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/ghunit/-/rxb6DVXV2H0J.

To post to this group, send email to ghu...@googlegroups.com.
To unsubscribe from this group, send email to ghunit+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ghunit?hl=en.

Joshua Moody

unread,
Nov 15, 2012, 4:49:51 PM11/15/12
to ghu...@googlegroups.com
sorry i did not post more details - super busy here.  i had the same problem as you (i think) after updating to iOS 6.

following the suggestions in that post, i subclassed UIApplication and provided the following init method

- (id)init {
  self = [super init];
  if (self != nil) {
    NSString *sysv = [[UIDevice currentDevice] systemVersion];
    NSLog(@"sys version = %@", sysv);
    if (getenv("GHUNIT_CLI") && [@"6.0" isEqualToString:sysv]) {
      if ([GHTestRunner run] > 0)
        [NSException raise:NSGenericException format:@""];
    }
  }
  return self;
}

my main.m looks like this:

int main(int argc, char *argv[]) {
  int retVal;
  @autoreleasepool {
    if (getenv("GHUNIT_CLI")) {
      // skip logging for command line builds
    } else {
      LjsDefaultFormatter *formatter = [[LjsDefaultFormatter alloc] init];
      DDTTYLogger *tty = [DDTTYLogger sharedInstance];
      [tty setLogFormatter:formatter];
      [DDLog addLogger:tty];
    }

    NSString *GHUNIT_DELEGATE;
#if TARGET_IPHONE_SIMULATOR 
    GHUNIT_DELEGATE = @"GHUnitIPhoneAppDelegate";
#else
    GHUNIT_DELEGATE = @"GHUnitIOSAppDelegate";
#endif
    # LjsApplicationTestRunnerIOS is my subclass
    retVal = UIApplicationMain(argc, argv, NSStringFromClass([LjsApplicationTestRunnerIOS class]), GHUNIT_DELEGATE);
  }
  return retVal;
}

jjm
Reply all
Reply to author
Forward
0 new messages