5 // Copyright (c) 2019 Apple Inc. All rights reserved.
10 #import <Foundation/Foundation.h>
11 #import <CoreUtils/CoreUtils.h>
12 #import <XCTest/XCTest.h>
15 #define XCTest_Framework_Runtime_Path "/AppleInternal/Developer/Library/Frameworks/XCTest.framework"
17 #define XCTest_Framework_Runtime_Path "/Developer/Library/Frameworks/XCTest.framework"
20 //===========================================================================================================================
22 //===========================================================================================================================
23 static NSBundle * LoadXCTestFramework()
25 NSBundle * result = nil;
26 Boolean loaded = (NSClassFromString(@"XCTestSuite") != nil);
29 result = [NSBundle bundleWithPath: @ XCTest_Framework_Runtime_Path];
31 loaded = (NSClassFromString(@"XCTestSuite") != nil);
33 FPrintF( stdout, "Failed to load XCTest framework from: %s\n", XCTest_Framework_Runtime_Path );
40 //===========================================================================================================================
42 //===========================================================================================================================
44 Boolean TestUtilsRunXCTestNamed(const char * classname)
46 Boolean result = false;
47 NSBundle * xctestFramework = LoadXCTestFramework();
50 NSString * name = [NSString stringWithUTF8String: classname];
51 NSBundle * testBundle = [NSBundle bundleWithPath: @"/AppleInternal/XCTests/com.apple.mDNSResponder/Tests.xctest"];
54 XCTestSuite * compiledSuite = [NSClassFromString(@"XCTestSuite") testSuiteForTestCaseWithName: name];
55 if(compiledSuite.tests.count) {
56 [compiledSuite runTest];
57 XCTestRun *testRun = compiledSuite.testRun;
58 result = (testRun.hasSucceeded != NO);
60 FPrintF( stdout, "Test class %s not found\n", classname );