Skip to content

Commit

Permalink
Outputing where JUnit XML files are written to. JUNIT_XML_DIR env
Browse files Browse the repository at this point in the history
for custom output dir.
  • Loading branch information
gabriel committed May 30, 2012
1 parent 096b536 commit 25dedb1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
15 changes: 14 additions & 1 deletion Classes/GHTest/GHTestRunner.m
Expand Up @@ -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"];
Expand Down
2 changes: 1 addition & 1 deletion Classes/GHTest/GHTestSuite.h
Expand Up @@ -111,7 +111,7 @@ extern NSString *GHUnitTest;

@interface GHTestSuite (JUnitXML)

- (BOOL)writeJUnitXML:(NSError **)error;
- (BOOL)writeJUnitXMLToDirectory:(NSString *)directory error:(NSError **)error;

@end

Expand Down
15 changes: 6 additions & 9 deletions Classes/GHTest/GHTestSuite.m
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Documentation/appledoc_include/guide_ci-template.markdown
Expand Up @@ -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.
Expand Down
Expand Up @@ -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.

0 comments on commit 25dedb1

Please sign in to comment.