Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

iOS: Re-running a test should respect shouldRunOnMainThread. #76

Closed
wants to merge 2 commits into from

4 participants

@Inferis

If you re-ran a test, the test was always run on the main thread. This is different behavior from the runs in the complete test suite.

These commits pass along the test group with the test to the detail controller, which then uses the context of the group to re-run the test. It actually creates a new group with the same context, with only (a copy of) the test to re-run in it.

Inferis added some commits
@Inferis Inferis Added initWithGroup to GHTestGroup. 776290c
@Inferis Inferis GHUnitIOSTestViewController now requires to be passed a test and its …
…group.

setTest: was modified to setTest:group:

This is necessary to properly rerun the test. Without the group the testCase's shouldRunOnMainThread isn't called, giving different behavior from this particular rerun versus the testsuite run.
23fa318
@x2on
Owner

+1
Thanks for this, i integrated this and it runs fine.

@drekka

Not sure if I've read this correctly, but I've just encountered a problem where a test works fine when run from the suite view, but crashes when run from the test view. The issue is the test includes threading code which assumes that it is not running on the main thread, but GHUnit runs the test on the main thread when the Run button is tapped.

I think I have the inverse of this bug in that I don't want it run on the main thread.

@Inferis

My changes will fix that.

@x2on
Owner

Is this relevant for the current master?

@x2on x2on closed this
@kolyuchiy

Yes, it's still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 24, 2012
  1. @Inferis
  2. @Inferis

    GHUnitIOSTestViewController now requires to be passed a test and its …

    Inferis authored
    …group.
    
    setTest: was modified to setTest:group:
    
    This is necessary to properly rerun the test. Without the group the testCase's shouldRunOnMainThread isn't called, giving different behavior from this particular rerun versus the testsuite run.
This page is out of date. Refresh to see the latest.
View
3  Classes-iOS/GHUnitIOSTestViewController.h
@@ -40,10 +40,11 @@
GHImageDiffView *imageDiffView_;
GHTestNode *testNode_;
+ GHTestGroup *group_;
GHTestRunner *runner_;
}
-- (void)setTest:(id<GHTest>)test;
+- (void)setTest:(id<GHTest>)test group:(id<GHTest>)group;
@end
View
17 Classes-iOS/GHUnitIOSTestViewController.m
@@ -44,6 +44,7 @@ - (id)init {
- (void)dealloc {
[testNode_ release];
+ [group_ release];
[super dealloc];
}
@@ -59,12 +60,16 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
- (void)_runTest {
- id<GHTest> test = [testNode_.test copyWithZone:NULL];
- NSLog(@"Re-running: %@", test);
+ NSLog(@"Re-running: %@", group_);
[testView_ setText:@"Running..."];
- [test run:GHTestOptionForceSetUpTearDownClass];
- [self setTest:test];
+
+ id<GHTest> test = [testNode_.test copyWithZone:nil];
+ GHTestGroup* group = [[GHTestGroup alloc] initWithGroup:group_ test:test];
+ [group run:GHTestOptionForceSetUpTearDownClass];
+ [self setTest:test group:group];
+
[test release];
+ [group release];
}
- (void)_showImageDiff {
@@ -101,12 +106,14 @@ - (NSString *)updateTestView {
return text;
}
-- (void)setTest:(id<GHTest>)test {
+- (void)setTest:(id<GHTest>)test group:(id<GHTest>)group {
[self view];
self.title = [test name];
[testNode_ release];
testNode_ = [[GHTestNode nodeWithTest:test children:nil source:nil] retain];
+ [group_ release];
+ group_ = [group retain];
NSString *text = [self updateTestView];
NSLog(@"%@", text);
}
View
2  Classes-iOS/GHUnitIOSViewController.m
@@ -204,7 +204,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
GHTestNode *testNode = [[sectionNode children] objectAtIndex:indexPath.row];
GHUnitIOSTestViewController *testViewController = [[GHUnitIOSTestViewController alloc] init];
- [testViewController setTest:testNode.test];
+ [testViewController setTest:testNode.test group:sectionNode.test];
[self.navigationController pushViewController:testViewController animated:YES];
[testViewController release];
}
View
4 Classes/GHTest/GHTestGroup.h
@@ -125,6 +125,10 @@
*/
- (id)initWithTestCase:(id)testCase selector:(SEL)selector delegate:(id<GHTestDelegate>)delegate;
+
+- (id)initWithGroup:(GHTestGroup*)group test:(id<GHTest>)test;
+
+
/*!
Create test group from a test case.
@param testCase Test case, could be a subclass of SenTestCase or GHTestCase
View
10 Classes/GHTest/GHTestGroup.m
@@ -72,6 +72,16 @@ - (id)initWithTestCase:(id)testCase selector:(SEL)selector delegate:(id<GHTestDe
return self;
}
+- (id)initWithGroup:(GHTestGroup*)group test:(id<GHTest>)test {
+ if ((self = [super init])) {
+ name_ = [group.name retain];
+ children_ = [[NSMutableArray arrayWithObject:test] retain];
+ delegate_ = group.delegate;
+ testCase_ = group.testCase;
+ }
+ return self;
+}
+
+ (GHTestGroup *)testGroupFromTestCase:(id)testCase delegate:(id<GHTestDelegate>)delegate {
return [[[GHTestGroup alloc] initWithTestCase:testCase delegate:delegate] autorelease];
}
Something went wrong with that request. Please try again.