Objective C Unit Test Setup - objective-c

I have been learning Objective C and Xcode for a few months now, and I am trying to setup some unit tests.
All of my projects are OS X "Command Line Tool" Applications. I use main.m to write code to test the methods and classes I've developed. That works fine. I'm trying to migrate to test targets and unit testing.
I am using "Testing with Xcode" as a guide, but I'm having some issues:
When I create a "Test Target", the "Target To Be Tested" field
defaults to "None", and can't be changed. Is that okay?
I am able to run the default tests. They pass. But when I create a new test that references a class method that I've written, I get a link error for each class method instance. (not a compile error)
My "ExampleTest.m" test target has an '#import "MyApp.h"', Is there any other setup I need to do?
The "Testing with Xcode" doc shows a setup test method that invokes the ViewController for the app being tested. I don't have a ViewController for my command line app, and I'm only trying to create unit tests, so I'm not sure how to modify that example...
Bonus Question: I have several classes that I add methods to, and want to reuse. How do I keep the unit tests with the source code for reuse? The Test Navigator hierarchy seems to be app-centric. How to others keep their classes and unit tests for those classes in sync?

OS X "Command Line Tool" applications do not include testing. Need to select "Cocoa Application" to include testing.

Related

How to add test case to testsuite in xcuitest?

I’m trying to run a custom test suite which includes several test cases. For example, I’ve wrote 4 test scripts(test_login_success,test_login_fail,test_register_xxx,test_register_yyy), and I just want to run test_login_* module, how to set the defaultTestSuite and add testcases to it?
The test cases you create belongs to its class. If you want to customise test runs you shall consider updating to the new Xcode 11. The new version of Xcode has test plans feature allowing you to control tests executions better.
Introduction video:
https://developer.apple.com/videos/play/wwdc2019/413/
If you prefer to stay on previous Xcode, you should add schemes for your scenarios.
Also, you can pass tests names in xcodebuild shell command.

How to create an SUnit test in Dolphin Smalltalk?

I've created a small (test) addition to the Dolphin Smalltalk framework
that I want to submit on GitHub later. (1 method: Integer>>isPrime)
But first, I want add my testing method of this method to the standard regression test set, with ~ 2400 tests now. (IntegerTest>>testIsPrime)
I've found the classes TestCase, DolphinTest, IntegerTest and the SUnit browser.
But I didn't find out how to add my test to the standard test set.
Can someone point me the right direction?
I assume you are working from a Git checkout and have the test classes in your image. From there the easiest thing is to modify an existing class (such as IntegerTest) in the code browser, save the package back to the file system, and then Git should show the files as modified.
The neat thing about SUnit is that by default it will include all methods that start with 'test' in the test suite. So just add the test, run the suite, and see the number of tests increase by one!

intellisense fails for file added to NUnit[Lite] project in Xamarin/Mono

I'm trying out Xamarin (on Mac OS X) to do some cross-platform (Mac, iOS, Android) development in Mono. I've created a "Point" class inside a "Filament" namespace, and now I'm trying to add unit tests.
There appear to be two approaches to unit testing in the Mono world: NUnit and NUnitLite. I've tried both (in the latter case, following this tutorial), with the same result, which is this:
In my unit test project, I add a link to the Point.cs file (by right-clicking the project, using 'Add...', selecting the file, and then choosing the "Add as Link" option). In my unit test file (PointTest.cs), I add "using Filament;" to the top of the file. But despite the fact that I can now use the Point class, and it successfully compiles, Intellisense seems completely oblivious to it -- every time I start to type "Point" it extends this to "PointTest", and when I doggedly change it back to Point, it draws it in red like an error.
In fact, the same trouble happened on my "using" line; I typed "using Filament" and it changed this to "using FilamentTestsiOS" (the namespace of my unit test project).
This is driving me nuts... but as a complete noob to Mono, Xamarin, NUnit, and NUnitLite, I'm sure I'm doing something stupid.
What's the correct way to set up a C#/Mono unit test, so that both intellisense and the compiler will recognize the classes for which I'm writing tests?

Xcode 4.4 unit test

First time trying to add unit test to my Xcode project. I added a test (LogicTests.h, LogicTests.m), linked it to a project in Target Dependencies. After that I created sample-class FDUnitTestClass and I want to test it with adding a simple math operation in it with logging result to Debug console. But I don't understand right way to do this. Do I need to define a method in .m of FDUnitTestClass, and if so how I can invoke it to see the log in console?
Some links that can help you:
Xcode Unit Testing Guide
Unit Testing in Xcode 4 Quick Start Guide

Any way to run code in SenTest only on a success?

In my Mac Cocoa unit tests, I would like to output some files as part of the testing process, and delete them when the test is done, but only when there are no failures. How can this be done (and/or what's the cleanest way to do so)?
Your question made me curious so I looked into it!
I guess I would override the failWithException: method in the class SenTestCase (the class your tests run in inherits from this), and set a "keep output files" flag or something before calling the super's method.
Here's what SenTestCase.h says about that method:
/*"Failing a test, used by all macros"*/
- (void) failWithException:(NSException *) anException;
So, provided you only use the SenTest macros to test and/or fail (and chances are this is true in your case), that should cover any test failure.
I've never dug into the scripts for this, but it seems like you could customize how you call the script that actually runs your tests to do this. In Xcode 4, look at the last step in the Build Phases tab of your test target. Mine contains this:
# Run the unit tests in this test bundle.
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
I haven't pored through the contents of this script or the many subscripts it pulls in on my machine, but presumably they call otest or some other test rig executable and the test results would be returned to that script. After a little time familiarizing yourself with those scripts you would likely be able to find a straightforward way to conditionally remove the output files based on the test results.