Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCTest not registering new methods as tests

Tags:

xcode

xctest

I have a seemingly weird problem (unless I'm missing something totally obvious!) and am curious if anyone here has any insight. I've done quite a bit of searching and haven't found anything.

When I try and write unit tests in XCTest - creating new methods - they don't seem to register as tests and aren't executed when I run the test suite. They also don't get one of those nice little diamond run buttons next to them that allows you to run individual tests: enter image description here

When using JUnit for example here you would annotate with @Test. Anything like this I'm missing?

like image 343
the1337sauce Avatar asked Mar 02 '14 18:03

the1337sauce


People also ask

Why choose xctest as your testing framework?

After some discussion, we chose XCTest as our testing framework. Our code base (excluding tests) has since grown to 544 kilobytes of source code spread across 190 files and 18,000 lines. Our tests click in at about 1,200 kilobytes, roughly twice that of the code they're testing.

How do you use xctest with Xcode?

The excellent integration into XCode speaks in XCTest's favor as well. You can press the diamond in the gutter to run just one test, you can easily display a list of failed tests, and you can quickly jump to a test by clicking on it in the list of tests. Unfortunately, that is also pretty much all you get.

How do I create a subclass of xctestcase?

Create a new subclass of XCTestCase within a test target. Add one or more test methods to the test case. Add one or more test assertions to each test method. A test method is an instance method on an XCTestCase subclass, with no parameters, no return value, and a name that begins with the lowercase word test.

What is the difference between xctest and JUnit?

XCTest, similarly to JUnit, invokes each test method on a separate instance of the test case. To illustrate with an example, imagine that you have ten test methods, the XCTest framework will instantiate ten instances of the test case class and invoke only one of the methods per instance.


3 Answers

Only method names that start with test are being recognized as tests. That way you can still use normal methods in your test classes that your actual test methods can call.

like image 88
Scott Berrevoets Avatar answered Sep 21 '22 05:09

Scott Berrevoets


Restart Xcode

New methods starting with test... were not being tested in my Test target.

- (void)testMethod {     // not tested } 

Solution was to restart Xcode.

like image 22
pkamb Avatar answered Sep 22 '22 05:09

pkamb


Your new method must begin with "test", after add it , cmd + B, you will find your new method on your test navigator.

like image 33
mistdon Avatar answered Sep 22 '22 05:09

mistdon