Skip to content

Instantly share code, notes, and snippets.

@yuchan
Last active August 29, 2015 14:07
Show Gist options
  • Save yuchan/fe4f3d5478d4466ab380 to your computer and use it in GitHub Desktop.
Save yuchan/fe4f3d5478d4466ab380 to your computer and use it in GitHub Desktop.
Generate XCTestCase subclasses from all source classes.
#!/usr/bin/env python
import os
XCTestCaseFormat = """//
// {ClassName}.m
// NrKj_iPhone
//
// Created by {Author} on {Date}.
//
//
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
@interface {ClassName} : XCTestCase
@end
@implementation {ClassName}
- (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 {{
// This is an example of a functional test case.
XCTAssert(YES, @"Pass");
}}
- (void)testPerformanceExample {{
// This is an example of a performance test case.
[self measureBlock:^{{
// Put the code you want to measure the time of here.
}}];
}}
@end
"""
def genT(root, test):
for f in os.listdir(root):
if not os.path.exists(test + root):
os.makedirs(test + root)
if f.find("+") == -1 and f.endswith(".m"):
comps = f.split('.')
testFile = comps[0] + "Test.m"
if not os.path.exists(test + root + "/" + testFile):
f = open(test+root+"/"+testFile, "w+")
s = XCTestCaseFormat.format(ClassName=comps[0]+"Test",Author="Yusuke Ohashi",Date="10/7/2014")
f.write(s)
f.close()
elif f.find(".") == -1:
try:
os.makedirs(test + root + "/" + f)
except:
pass
genT(root + "/" + f, test)
# How to
# os.chdir("go to root dir")
# genT("./Sources", "Tests/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment