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:
When using JUnit for example here you would annotate with @Test. Anything like this I'm missing?
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.
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.
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.
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.
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.
New methods starting with test...
were not being tested in my Test target.
- (void)testMethod { // not tested }
Solution was to restart Xcode.
Your new method must begin with "test", after add it , cmd + B, you will find your new method on your test navigator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With