Skip to content
This repository has been archived by the owner on Jun 5, 2018. It is now read-only.

Some Test Suite Additions #120

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 28 additions & 2 deletions Classes-iOS/GHUnitIOSViewController.m
Expand Up @@ -91,8 +91,34 @@ - (void)viewDidAppear:(BOOL)animated {

- (GHUnitIOSTableViewDataSource *)dataSource {
if (!dataSource_) {
dataSource_ = [[GHUnitIOSTableViewDataSource alloc] initWithIdentifier:@"Tests" suite:[GHTestSuite suiteFromEnv]];
[dataSource_ loadDefaults];
// Conditionally grab an custom Test Suite from GH_UNIT_CLASSSUITE environment.
const char* cClassSuite = getenv("GH_UNIT_CLASSSUITE");
if (cClassSuite) {
NSString *name = [NSString stringWithUTF8String:cClassSuite];
Class customClassSuite = NSClassFromString( name );

//////////////////////////////////// ////////////////////////////////////
// Init the suite.
GHTestSuite *anSuite = [[customClassSuite alloc] initWithName:name delegate:nil];

// If can't initialize, raise exception.
if ( anSuite == nil ) {
[NSException raise:NSInternalInconsistencyException
format:@"The Test Suite Class '%@' defined in 'GH_UNIT_CLASSSUITE' enviroment variable can't be initiated. Please check!", name];
return nil;
}

////////////////////////////////////
// Init the Data Source.
dataSource_ = [[GHUnitIOSTableViewDataSource alloc] initWithIdentifier:name suite:anSuite];
}

////////////////////////////////////
// Default Class Suite.
else {
dataSource_ = [[GHUnitIOSTableViewDataSource alloc] initWithIdentifier:@"Tests" suite:[GHTestSuite suiteFromEnv]];
[dataSource_ loadDefaults];
}
}
return dataSource_;
}
Expand Down
15 changes: 15 additions & 0 deletions Classes/GHTest/GHTestGroup.h
Expand Up @@ -132,6 +132,21 @@
*/
+ (GHTestGroup *)testGroupFromTestCase:(id)testCase delegate:(id<GHTestDelegate>)delegate;

/*!
Create test group from a test case Class Name.
@param anClassName <tt>NSString</tt> with the class of this test case.
@param delegate Delegate, notifies of test start and end
@result New test group
*/
+ (GHTestGroup *)testGroupFromTestCaseClassName:(NSString*)anClassName delegate:(id<GHTestDelegate>)delegate;

/*!
Create an test case from an Class name.
@param anClassName <tt>NSString</tt> with the class of this test case.
@result New autoreleseable Test Case or <tt>nil</tt> if can't initialize.
*/
+ (GHTestCase*)testCaseFromClassName:(NSString*)anClassName;

/*!
Add a test case (or test group) to this test group.
@param testCase Test case, could be a subclass of SenTestCase or GHTestCase
Expand Down
9 changes: 9 additions & 0 deletions Classes/GHTest/GHTestGroup.m
Expand Up @@ -75,6 +75,15 @@ + (GHTestGroup *)testGroupFromTestCase:(id)testCase delegate:(id<GHTestDelegate>
return [[GHTestGroup alloc] initWithTestCase:testCase delegate:delegate];
}

+ (GHTestGroup *)testGroupFromTestCaseClassName:(NSString*)anClassName delegate:(id<GHTestDelegate>)delegate {
return [[GHTestGroup alloc] initWithTestCase:[self testCaseFromClassName:anClassName]
delegate:delegate];
}

+ (GHTestCase*)testCaseFromClassName:(NSString*)anClassName {
return [[NSClassFromString(anClassName) alloc] init];
}

- (void)dealloc {
for(id<GHTest> test in children_)
[test setDelegate:nil];
Expand Down
25 changes: 25 additions & 0 deletions Classes/GHTest/GHTestSuite.h
Expand Up @@ -55,6 +55,31 @@ extern NSString *GHUnitTest;
- (void)testB1; (GHTest with target GHTestCase2 + testB1)
- (void)testB2; (GHTest with target GHTestCase2 + testB2)

If you want to create an custom Test Suite to your iPhone Application in order to have more control
over the Test Cases follow this steps:

Create your own subclasse of GHTestSuite.
Here is an example:

@interface myTestSuite : GHTestSuite {}
@end

@implementation myTestSuite
- (id)initWithName:(NSString *)name delegate:(id<GHTestDelegate>)delegate {
[super initWithName:name delegate:delegate];

[self addTestGroup:
[GHTestGroup testGroupFromTestCaseClassName:@"myTestCaseForDelegates" delegate:nil]];

[self addTestGroup:
[GHTestGroup testGroupFromTestCaseClassName:@"myTestCaseForClasses" delegate:nil]];
}

Once that you have your Test Suite created, <b>you must inform that you will use an custom Suite Class</b>.
To do that, open your executable properties and under Arguments > Variables to be set in the environment,
create a new record named <tt>GH_UNIT_CLASSSUITE</tt> and set <tt>myTestSuite</tt> as value.

Now when you run, the test application will use your custom <b>Test Suite Class</b>.
*/
@interface GHTestSuite : GHTestGroup { }

Expand Down