iOS Test Failure - "No Implementation for…" - ios

After completing my app I run a test from Xcode, Product -> Test, it says 'Build Succeeded' and the app pops up for a split second, but then it prompt me with this message:
I have searched a lot but couldn't find any solution that works in this case. I want to mention that I have also tried changing the name of the application from, CSQTCConference, to CSQTC Conference, not sure how relevant this is.
I am planning to release my application to app store today, but this issue is holding it back. It will be helpful if you can suggest any pointers to resolve this issue.

I just comment the following line:
//XCTFail(#"No implementation for \"%s\"", __PRETTY_FUNCTION__);
in:
#import <XCTest/XCTest.h>
#interface KinderAppTests : XCTestCase
#end
#implementation KinderAppTests
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testExample
{
//XCTFail(#"No implementation for \"%s\"", __PRETTY_FUNCTION__);
}
#end
This solution worked for me, hope it helps :)

I'm not familiar with XCTest but I assume XCTFail will always fail, so no big surprise here.
You are running boilerplate example code, which created a test that always fails. If you haven't written your own tests what's the point of running them in the first place?

The real question is: Why is this happening?
Answer: You did a Command U, or selected test. This ran the default test, which always fails.
Correction: Comment out the fail line, and run it again.

Related

Newly created test case class is not shown under Test Navigator in Xcode

My XCode version is 7.3.1 .
My project already has test project, and there are already some test case classes. I can see them when select the "Test Navigator" tab which is one of this on left top of XCode.
Now, I want to create a new test case, so I selected the new Unit Test Case Class:
And I add very simple code into it:
#import <XCTest/XCTest.h>
#interface MyTest : XCTestCase
#end
#implementation MyTest
- (void)setUp {
[super setUp];
}
- (void)tearDown {
[super tearDown];
}
- (void)testExample {
NSString* expected = #"my-test-string";
XCTAssertEqual(expected, #"my-test-string");
}
#end
I need to run it, so I go to "Test Navigator" again, but I can't see this test case class I just created. Why?
Restarting Xcode is the only thing that worked for me in Xcode 9.0 beta 6.
It appears that Xcode adds the individual testmethods/classes only after the whole unit test target has been run at least once.
So select your test target, run all tests using Command u. After that you should see all tests in the test navigator and you can run them individually.
Sometimes the unit test appears in Test Navigator after you Save (CTRL+S) the unit test's file in XCode.
Remember to keep the test prefix on the test methods, otherwise they are not recognized by the test framework, e.g.:
func test_When_empty_Then_returnsNil() {
not
func when_empty_Then_returnsNil() {

iOS testing with XCTest and separate file

Currently, I write my testing in 1 file (default). Is it possible to have multiple files and test?
- (void)setUp {
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testExample {
// This is an example of a functional test case.
XCTAssert(YES, #"Pass");
}
You can have many files and many tests per file. The first one is just the one made by Xcode automatically, but all that makes it special is that it:
Implements a subclass of XCTestCase
Is a member of the testing target (not your app target)
Making another file with the same characteristics is simple.
In Xcode, File -> New -> iOS -> Source -> UI Test Case Class
The convention is to group related tests into a source file, and then name that source file ___Tests.swift (or .m)
For example, SharingTests.swift might contain the methods testSharingToFacebook() and testSharingToTwitter().

How To Run XCTest in Xcode 5.1

I'm trying the XCTest framework
#implementation UnitTestPOCTests
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testAditionClass
{
Addition *addObj = [[Addition alloc]init];
XCTAssertNotNil(addObj,#"AddtionClassExists");
}
I wrote the testAditionClass test method inside my test class, but when i run the test methods its showing Testing.... in the status bar
its not even getting terminated.
If any one know the the solution please help me.
Thanks in advance
I resolved this problem by opening the simulator you will have the following options in menu
if you tap on reset content and setting.
Then try running unit test it works for me.

NSLog Not Displaying At All

I have just begun using XCode to explore Objective C. It seems my NSLog command has absolutely no result, whatsoever. I have tried to 'Activate Console', and have made sure that All Output is selected for my console. In ViewController.m, I am using this code to test the problem:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(#"Testing");
}
There is no output. Please help! Thanks.
Sometimes the console got deactivated. Press Shift +  + C, the console will be activated again.
Here is a link to devforums. Hope this helps... :)
This also occur in iOS10 when "OS_ACTIVITY_MODE = disabled" is set in the Run Arguments for your scheme
The Swift print function still works. So you can create a Swift function which prints your strings.
Check if your view ever got called. (initialized)
If it's not then it makes sense the NSLog is never reached in viewDidLoad
Do you have anything like this in your .pch file?
#define NSLog
This basically replaces NSLog with nothing when it's compiled.

EXC_BAD_ACCESS using ARC only during testing

I have an issue where I'm getting bad access exceptions but only when running a testing build (calling the same methods in a debug build doesn't cause the problem to come up). The project has ARC enabled and I'm running this on the iPad 5.1 simulator using Xcode 4.3:
Here's where the problem crops up:
- (void)testChangeFoodNotification {
Player* p = [[Player alloc] init];
[p addObserver:self forKeyPath:#"food" options:0 context:0]; // <-EXC_BAD_ACCESS (code=2)
p.food += 1;
STAssertTrue(_wasNotifiedOfFoodChange, nil);
}
At the point when the addObserver: method is called it doesn't seem like any of the objects involved should have been released so what could be causing the exception?
EDIT:
Apologies if it wasn't clear but the code above is being executed as part of a test case (using the standard Xcode OCUnit). Also in case it clarifies anything here's the relevant code from the player class (there's other ivars and methods but they don't have any connection to the property or methods being tested):
// Public interface
#interface Player : NSObject
#property (nonatomic, assign) NSInteger food;
#end
// Private interface
#interface Player() {
NSInteger _food;
}
#end
#implementation Player
#synthesize food = _food;
#pragma mark - Getters/Setters
- (void)setFood:(NSInteger)food {
[self willChangeValueForKey:#"food"];
_food = food;
[self didChangeValueForKey:#"food"];
}
If your class is indeed key-value compliant, ensure that the implementation for the class exhibiting the issue is not included in your test product. This means that the Target Membership panel of the Identity inspector for your .m file should only have your app checked (not YourAppTests).
I experienced the same issue in Xcode 4.3.1 when an implementation was included in both products and I registered observers in both production and test code. The following logs tipped me off:
Class YourClass is implemented in both /Users/yourUser/Library/Application Support/iPhone Simulator/5.1/Applications//YourApp.app/YourApp and /Users/yourUser/Library/Developer/Xcode/DerivedData/YourApp-/Build/Products/Debug-iphonesimulator/YourAppTests.octest/YourAppTests. One of the two will be used. Which one is undefined.
As per the Key-Value Observing Programming Guide, is your Player key-value-compliant? You want to make sure you are Ensuring KVC Compliance. I also assume that you have also implemented your observeValueForKeyPath:ofObject:change:context:? If you think you've done all of this and it's still not working, then perhaps you can share your code.
Also, minor thing, but I assume this is a code snippet to highlight the issue. I only mention it because ARC is going to be releasing your p object at the end of your testChangeFoodNotification and I would have thought that you'd want to remove your observer first.

Resources