diff --git a/Classes/GHTest/GHTestRunner.m b/Classes/GHTest/GHTestRunner.m index 2b2ed279..03681d34 100644 --- a/Classes/GHTest/GHTestRunner.m +++ b/Classes/GHTest/GHTestRunner.m @@ -276,7 +276,20 @@ - (void)_notifyFinished { // Log JUnit XML if environment variable is set if (getenv("WRITE_JUNIT_XML")) { NSError *error = nil; - if (![testSuite writeJUnitXML:&error]) { + + NSString *resultsDir; + + char *resultsDirStr = getenv("JUNIT_XML_DIR"); + if (resultsDirStr) { + resultsDir = [NSString stringWithUTF8String:resultsDirStr]; + } else { + NSString *tmpDir = NSTemporaryDirectory(); + resultsDir = [tmpDir stringByAppendingPathComponent:@"test-results"]; + } + + [self log:[NSString stringWithFormat:@"Writing JUnit XML to:%@.\n", resultsDir]]; + + if (![testSuite writeJUnitXMLToDirectory:resultsDir error:&error]) { [self log:[NSString stringWithFormat:@"Error writing JUnit XML: %@\n", [error localizedDescription]]]; } else { [self log:@"Wrote JUnit XML successfully.\n"]; diff --git a/Classes/GHTest/GHTestSuite.h b/Classes/GHTest/GHTestSuite.h index 93116144..d35cc11b 100644 --- a/Classes/GHTest/GHTestSuite.h +++ b/Classes/GHTest/GHTestSuite.h @@ -111,7 +111,7 @@ extern NSString *GHUnitTest; @interface GHTestSuite (JUnitXML) -- (BOOL)writeJUnitXML:(NSError **)error; +- (BOOL)writeJUnitXMLToDirectory:(NSString *)directory error:(NSError **)error; @end diff --git a/Classes/GHTest/GHTestSuite.m b/Classes/GHTest/GHTestSuite.m index 32c868d2..3012bdb0 100644 --- a/Classes/GHTest/GHTestSuite.m +++ b/Classes/GHTest/GHTestSuite.m @@ -139,25 +139,22 @@ @implementation GHTestSuite (JUnitXML) Override logic to write children individually, as we want each test group's JUnit XML to be in its own file. */ -- (BOOL)writeJUnitXML:(NSError **)error { +- (BOOL)writeJUnitXMLToDirectory:(NSString *)directory error:(NSError **)error { NSParameterAssert(error); BOOL allSuccess = YES; NSFileManager *fileManager = [NSFileManager defaultManager]; - NSString *tmpDir = NSTemporaryDirectory(); - NSString *resultsDir = [tmpDir stringByAppendingPathComponent:@"test-results"]; - - if (![fileManager fileExistsAtPath:resultsDir]) { - if (![fileManager createDirectoryAtPath:resultsDir withIntermediateDirectories:YES attributes:nil error:error]) { - NSLog (@"Error while creating results directory: %@", [*error localizedDescription]); + if (![fileManager fileExistsAtPath:directory]) { + if (![fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:error]) { + NSLog(@"Error while creating results directory: %@", [*error localizedDescription]); return NO; } } for (id child in self.children) { if ([child respondsToSelector:@selector(writeJUnitXMLAtPath:error:)]) { - if (![child writeJUnitXMLAtPath:resultsDir error:error]) { - NSLog (@"Error writing JUnit XML: %@", [*error localizedDescription]); + if (![child writeJUnitXMLAtPath:directory error:error]) { + NSLog(@"Error writing JUnit XML: %@", [*error localizedDescription]); allSuccess = NO; } } diff --git a/Documentation/appledoc_include/guide_ci-template.markdown b/Documentation/appledoc_include/guide_ci-template.markdown index bc9a7ec4..1bf8719a 100644 --- a/Documentation/appledoc_include/guide_ci-template.markdown +++ b/Documentation/appledoc_include/guide_ci-template.markdown @@ -15,12 +15,12 @@ want to configure `Source Code Management`, and then under `Build Triggers` chec - Under `Build`, enter the following command: - make clean && WRITE_JUNIT_XML=YES make test + make clean && WRITE_JUNIT_XML=YES JUNIT_XML_DIR=tmp/test-results make test - Under `Post-build Actions`, check `Publish JUnit test result report` and enter the following in `Test report XMLs`: - build/test-results/*.xml + tmp/test-results/*.xml That's all it takes. Check in a change that breaks one of your tests. Hudson should detect the change, run a build and test, and then report the failure. Fix the test, check in again, and you should see a successful build report. diff --git a/Documentation/appledoc_include/guide_command_line-template.markdown b/Documentation/appledoc_include/guide_command_line-template.markdown index b1c7851e..d26acd2e 100644 --- a/Documentation/appledoc_include/guide_command_line-template.markdown +++ b/Documentation/appledoc_include/guide_command_line-template.markdown @@ -63,4 +63,5 @@ The `TEST` environment variable can be used to run a single test or test case. - `GHUNIT_AUTOEXIT`: Default NO; If YES, will exit upon test completion (no matter what). For command line MacOSX testing - `GHUNIT_CLI`: Default NO; Specifies that the tests are being run from the command line. For command line MacOSX testing - `WRITE_JUNIT_XML`: Default NO; Whether to write out JUnit XML output. For Jenkins CI integration +- `JUNIT_XML_DIR`: Default to temporary directory. Specify to have files written to a different directory. For Jenkins CI integration.