Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Some Test Suite Additions #120

Closed
wants to merge 1 commit into from

2 participants

Paulo Oliveira Felix Schulze
Paulo Oliveira

More control for test suites.

Felix Schulze
Owner

What does this pull request do? Can you please explain it?

Felix Schulze x2on closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2013
  1. Paulo Oliveira

    Test Suite Additions

    seqoy authored
This page is out of date. Refresh to see the latest.
30 Classes-iOS/GHUnitIOSViewController.m
View
@@ -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_;
}
15 Classes/GHTest/GHTestGroup.h
View
@@ -133,6 +133,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
*/
9 Classes/GHTest/GHTestGroup.m
View
@@ -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];
25 Classes/GHTest/GHTestSuite.h
View
@@ -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 { }
Something went wrong with that request. Please try again.