Last active
October 3, 2019 18:17
-
-
Save hoshi-takanori/8208342 to your computer and use it in GitHub Desktop.
Testing Objective-C class by XCTest with plain old Makefile in command line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MyObject.h" | |
int main() | |
{ | |
@autoreleasepool { | |
MyObject *myObject = [[MyObject alloc] init]; | |
NSLog(@"myObject = %@", myObject); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CLASS_NAME = MyObject | |
OBJS = main.o $(CLASS_NAME).o $(CLASS_NAME)Tests.o | |
PROGRAM = a.out | |
CFLAGS = -Wall -F$(FWPATH) | |
LIBS = -F$(FWPATH) -framework XCTest -framework Foundation | |
FWPATH = /Applications/Xcode.app/Contents/Developer/Library/Frameworks | |
XCTEST = /Applications/Xcode.app/Contents/Developer/usr/bin/xctest | |
$(PROGRAM): $(OBJS) | |
$(CC) -o $(PROGRAM) $(OBJS) $(LIBS) | |
test: $(PROGRAM) | |
DYLD_FRAMEWORK_PATH=$(FWPATH) $(XCTEST) -XCTest $(CLASS_NAME)Tests $(PROGRAM) | |
clean: | |
$(RM) -rf $(PROGRAM) *.o | |
$(OBJS): $(CLASS_NAME).h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface MyObject : NSObject | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MyObject.h" | |
@implementation MyObject | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <XCTest/XCTest.h> | |
#import "MyObject.h" | |
@interface MyObjectTests : XCTestCase | |
@end | |
@implementation MyObjectTests | |
- (void)setUp | |
{ | |
[super setUp]; | |
// Put setup code here. This method is called before the invocation of each test method in the class. | |
} | |
- (void)tearDown | |
{ | |
// Put teardown code here. This method is called after the invocation of each test method in the class. | |
[super tearDown]; | |
} | |
- (void)testExample | |
{ | |
MyObject *myObject = [[MyObject alloc] init]; | |
XCTAssert(myObject != nil, @"myObject is successfully created."); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, Could you please explain (for dummies like me), how you run this make file from the Terminal (command line)?
I follow the logic but I can't make it work.
Thank you