Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run only one test case #52

Closed
GoogleCodeExporter opened this issue Apr 21, 2015 · 10 comments
Closed

Run only one test case #52

GoogleCodeExporter opened this issue Apr 21, 2015 · 10 comments

Comments

@GoogleCodeExporter
Copy link

IPhone SDK :

Impossible to run only one test case as you would do with other unit test 
framework. You have to run all tests which takes too much time when doing TDD 
or when debugging a single test.

Original issue reported on code.google.com by vdau...@gmail.com on 11 Jun 2010 at 3:34

@GoogleCodeExporter
Copy link
Author

I think this is a must for TDD

Original comment by agens.an...@gmail.com on 13 Oct 2010 at 8:59

@GoogleCodeExporter
Copy link
Author

Is the only way to restrict the tests that run to create multiple testing 
executables that build against different test files?

Original comment by PaulSolt on 5 Dec 2010 at 9:26

@GoogleCodeExporter
Copy link
Author

Dave - What is the env variable trick you use to control what is run?

Original comment by thoma...@gmail.com on 6 Dec 2010 at 1:13

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

In GHUnit, which is similar to GTMUnit I can pass a command line argument to 
the executable to limit tests. Is something like that possible in GTM?

For example, in the Xcode executable for the test target add an argument called 
TEST and provide the name of the test class to run, or the test class/test 
function name to restrict it even further.

See "Running a Test Case / Single Test"
http://gabriel.github.com/gh-unit/_command_line.html

Original comment by PaulSolt on 6 Dec 2010 at 6:38

Attachments:

@GoogleCodeExporter
Copy link
Author

That would be just great ! has anybody been able to achieve this with GTM ?

Original comment by vdau...@gmail.com on 13 Dec 2010 at 5:01

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

If there isn't a workaround, you might want to consider switching to GHUnit. I 
reviewed three test frameworks: OCUnit, GTMUnit, and GHUnit here:
http://paulsolt.com/2010/11/iphone-unit-testing-explained-part-1/

Original comment by PaulSolt on 13 Dec 2010 at 5:49

@GoogleCodeExporter
Copy link
Author

Our workaround has been to create an additional test target containing 
everything but actual tests. Then in an ad-hoc fashion, you can add a test to 
the target. This is problematic because you have to remember to remove it again 
before submitting changes.

Original comment by jon.m.r...@gmail.com on 24 Jan 2011 at 5:53

@GoogleCodeExporter
Copy link
Author

Here's a (not very pretty) patch, simply add -DGTM_TEST=NameOfTestClass to the 
CFLAGS of the unit test target.

If GTM_TEST isn't defined, all tests are run.

--- GTMIPhoneUnitTestDelegate.m (revision 439)
+++ GTMIPhoneUnitTestDelegate.m (working copy)
@@ -27,6 +27,9 @@
 #import <UIKit/UIKit.h>
 #import "GTMSenTestCase.h"

+#define CONVERT_SYMBOL_TO_NSSTRING_2(x) @#x
+#define CONVERT_SYMBOL_TO_NSSTRING(x) CONVERT_SYMBOL_TO_NSSTRING_2(x)
+
 @interface UIApplication (GTMIPhoneUnitTestDelegate)

 // SPI that we need to exit cleanly with a value.
@@ -105,12 +108,33 @@
 // that are subclasses of SenTestCase. Print results and run time to
 // the default output.
 - (void)runTests {
-  int count = objc_getClassList(NULL, 0);
-  NSMutableData *classData
+    int count = 0;
+    
+    Class *classes = nil;
+    
+#ifdef GTM_TEST
+    Class testClass = NSClassFromString(CONVERT_SYMBOL_TO_NSSTRING(GTM_TEST));
+    
+    _GTMDevAssert(testClass, @"Couldn't find GTM_TEST test class");
+    
+    if(testClass)
+    {
+        Class singleTestClass[1];
+        singleTestClass[0] = testClass;
+        classes = singleTestClass;
+        count = 1;
+    }
+#else
+    count = objc_getClassList(NULL, 0);
+    
+    NSMutableData *classData
     = [NSMutableData dataWithLength:sizeof(Class) * count];
-  Class *classes = (Class*)[classData mutableBytes];
-  _GTMDevAssert(classes, @"Couldn't allocate class list");
-  objc_getClassList(classes, count);
+    classes = (Class*)[classData mutableBytes];
+    
+    _GTMDevAssert(classes, @"Couldn't allocate class list");
+    objc_getClassList(classes, count);
+#endif
+    
   totalFailures_ = 0;
   totalSuccesses_ = 0;
   NSString *suiteName = [[NSBundle mainBundle] bundlePath];

Original comment by insertwi...@gmail.com on 7 Apr 2011 at 8:02

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants